Skip to content

Instantly share code, notes, and snippets.

@ironfounderson
Created October 18, 2010 12:22

Revisions

  1. ironfounderson revised this gist Oct 18, 2010. 1 changed file with 35 additions and 35 deletions.
    70 changes: 35 additions & 35 deletions gistfile1.cs
    Original file line number Diff line number Diff line change
    @@ -1,43 +1,43 @@
    class EventTimeTest
    {
    public event EventHandler StandardEvent;
    public event EventHandler TrickyEvent = delegate { };
    public event EventHandler StandardEvent;
    public event EventHandler TrickyEvent = delegate { };

    public void Test() {
    Stopwatch timer;
    EventArgs e = new EventArgs();
    for (int testCase = 0; testCase < 9; testCase++) {
    int limit = (int)Math.Pow(10, testCase);
    timer = new Stopwatch();
    timer.Start();
    for (int iteration = 0; iteration < limit; iteration++) {
    OnStandardEvent(e);
    }
    timer.Stop();
    double standardMs = timer.ElapsedMilliseconds;
    double standardTicks = timer.ElapsedTicks;
    timer = new Stopwatch();
    timer.Start();
    for (int iteration = 0; iteration < limit; iteration++) {
    OnTrickyEvent(e);
    }
    timer.Stop();
    public void Test() {
    Stopwatch timer;
    EventArgs e = new EventArgs();
    for (int testCase = 0; testCase < 9; testCase++) {
    int limit = (int)Math.Pow(10, testCase);
    timer = new Stopwatch();
    timer.Start();
    for (int iteration = 0; iteration < limit; iteration++) {
    OnStandardEvent(e);
    }
    timer.Stop();
    double standardMs = timer.ElapsedMilliseconds;
    double standardTicks = timer.ElapsedTicks;
    timer = new Stopwatch();
    timer.Start();
    for (int iteration = 0; iteration < limit; iteration++) {
    OnTrickyEvent(e);
    }
    timer.Stop();

    double msDifference = standardMs != 0 ? timer.ElapsedMilliseconds/standardMs : 0;
    double tickDifference = standardTicks != 0 ? timer.ElapsedTicks/standardTicks : 0;
    double msDifference = standardMs != 0 ? timer.ElapsedMilliseconds/standardMs : 0;
    double tickDifference = standardTicks != 0 ? timer.ElapsedTicks/standardTicks : 0;

    Console.WriteLine("{0}: MS Standard: {1} Tricky: {2} Difference {3}", limit, standardMs, timer.ElapsedMilliseconds, msDifference);
    Console.WriteLine("{0}: Ticks Standard: {1} Tricky: {2} Difference {3}", limit, standardTicks, timer.ElapsedTicks, tickDifference);
    }
    }
    Console.WriteLine("{0}: MS Standard: {1} Tricky: {2} Difference {3}", limit, standardMs, timer.ElapsedMilliseconds, msDifference);
    Console.WriteLine("{0}: Ticks Standard: {1} Tricky: {2} Difference {3}", limit, standardTicks, timer.ElapsedTicks, tickDifference);
    }
    }

    private void OnStandardEvent(EventArgs e) {
    if (StandardEvent != null) StandardEvent(this, e);
    }
    private void OnStandardEvent(EventArgs e) {
    if (StandardEvent != null) StandardEvent(this, e);
    }

    private void OnTrickyEvent(EventArgs e) {
    TrickyEvent(this, e);
    }
    private void OnTrickyEvent(EventArgs e) {
    TrickyEvent(this, e);
    }
    }
  2. ironfounderson revised this gist Oct 18, 2010. 1 changed file with 42 additions and 67 deletions.
    109 changes: 42 additions & 67 deletions gistfile1.cs
    Original file line number Diff line number Diff line change
    @@ -1,68 +1,43 @@
    class EventTimeTest
    {
    public event EventHandler StandardEvent;
    public event EventHandler TrickyEvent = delegate { };

    public void Test()
    {
    Stopwatch timer;



    EventArgs e = new EventArgs();
    for (int testCase = 0; testCase < 9; testCase++)
    {
    int limit = (int)Math.Pow(10, testCase);



    timer = new Stopwatch();
    timer.Start();
    for (int iteration = 0; iteration < limit; iteration++)
    {
    OnStandardEvent(e);
    }
    timer.Stop();
    double standardMs = timer.ElapsedMilliseconds;
    double standardTicks = timer.ElapsedTicks;



    timer = new Stopwatch();
    timer.Start();
    for (int iteration = 0; iteration < limit; iteration++)
    {
    OnTrickyEvent(e);
    }
    timer.Stop();



    double msDifference = standardMs != 0 ? timer.ElapsedMilliseconds/standardMs : 0;
    double tickDifference = standardTicks != 0 ? timer.ElapsedTicks/standardTicks : 0;



    Console.WriteLine("{0}: MS Standard: {1} Tricky: {2} Difference {3}",
    limit, standardMs, timer.ElapsedMilliseconds, msDifference);
    Console.WriteLine("{0}: Ticks Standard: {1} Tricky: {2} Difference {3}",
    limit, standardTicks, timer.ElapsedTicks, tickDifference);

    }
    }



    private void OnStandardEvent(EventArgs e)
    {
    if (StandardEvent != null)
    StandardEvent(this, e);
    }



    private void OnTrickyEvent(EventArgs e)
    {
    TrickyEvent(this, e);
    }
    class EventTimeTest
    {
    public event EventHandler StandardEvent;
    public event EventHandler TrickyEvent = delegate { };

    public void Test() {
    Stopwatch timer;
    EventArgs e = new EventArgs();
    for (int testCase = 0; testCase < 9; testCase++) {
    int limit = (int)Math.Pow(10, testCase);
    timer = new Stopwatch();
    timer.Start();
    for (int iteration = 0; iteration < limit; iteration++) {
    OnStandardEvent(e);
    }
    timer.Stop();

    double standardMs = timer.ElapsedMilliseconds;
    double standardTicks = timer.ElapsedTicks;

    timer = new Stopwatch();
    timer.Start();
    for (int iteration = 0; iteration < limit; iteration++) {
    OnTrickyEvent(e);
    }
    timer.Stop();

    double msDifference = standardMs != 0 ? timer.ElapsedMilliseconds/standardMs : 0;
    double tickDifference = standardTicks != 0 ? timer.ElapsedTicks/standardTicks : 0;

    Console.WriteLine("{0}: MS Standard: {1} Tricky: {2} Difference {3}", limit, standardMs, timer.ElapsedMilliseconds, msDifference);
    Console.WriteLine("{0}: Ticks Standard: {1} Tricky: {2} Difference {3}", limit, standardTicks, timer.ElapsedTicks, tickDifference);
    }
    }

    private void OnStandardEvent(EventArgs e) {
    if (StandardEvent != null) StandardEvent(this, e);
    }

    private void OnTrickyEvent(EventArgs e) {
    TrickyEvent(this, e);
    }
    }
  3. ironfounderson created this gist Oct 18, 2010.
    68 changes: 68 additions & 0 deletions gistfile1.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    class EventTimeTest
    {
    public event EventHandler StandardEvent;
    public event EventHandler TrickyEvent = delegate { };

    public void Test()
    {
    Stopwatch timer;



    EventArgs e = new EventArgs();
    for (int testCase = 0; testCase < 9; testCase++)
    {
    int limit = (int)Math.Pow(10, testCase);



    timer = new Stopwatch();
    timer.Start();
    for (int iteration = 0; iteration < limit; iteration++)
    {
    OnStandardEvent(e);
    }
    timer.Stop();
    double standardMs = timer.ElapsedMilliseconds;
    double standardTicks = timer.ElapsedTicks;



    timer = new Stopwatch();
    timer.Start();
    for (int iteration = 0; iteration < limit; iteration++)
    {
    OnTrickyEvent(e);
    }
    timer.Stop();



    double msDifference = standardMs != 0 ? timer.ElapsedMilliseconds/standardMs : 0;
    double tickDifference = standardTicks != 0 ? timer.ElapsedTicks/standardTicks : 0;



    Console.WriteLine("{0}: MS Standard: {1} Tricky: {2} Difference {3}",
    limit, standardMs, timer.ElapsedMilliseconds, msDifference);
    Console.WriteLine("{0}: Ticks Standard: {1} Tricky: {2} Difference {3}",
    limit, standardTicks, timer.ElapsedTicks, tickDifference);

    }
    }



    private void OnStandardEvent(EventArgs e)
    {
    if (StandardEvent != null)
    StandardEvent(this, e);
    }



    private void OnTrickyEvent(EventArgs e)
    {
    TrickyEvent(this, e);
    }
    }