Created
October 18, 2010 12:22
-
-
Save ironfounderson/632115 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment