All the following times are for one million iterations.
| Technique | Milliseconds |
| ActiveSharp | 400 |
| StackWalk | 120000 |
| MethodBase.GetCurrentMethod() | 2000 |
| "string" | 20 |
| const string | 10 |
The speed of ActiveSharp is a little unrealistic because it caches the Property Name for each field in the class. A class with more properties or accessing many different objects would reduce the speed advantage.
Since the StackWalk was so slow I decided to check whether it was my code (examining the stack) or the creation of the stack in the first instance.
private void Button_Click_2(object sender, RoutedEventArgs e)
{
DateTime start = DateTime.Now;
for (int i = 0; i <= 1000000; i++)
{
StackTrace trace = new StackTrace();
}
DateTime end = DateTime.Now;
MessageBox.Show(end.Subtract(start).TotalMilliseconds.ToString());
}One million iterations took 118,000 milliseconds to complete. There is little point trying to improve my code further.
No comments:
Post a Comment