Checking the Performance of Enum.GetName vs ToString
Stopwatch w = new Stopwatch();
w.Start();
for (int i = 0; i < 10000; i++)
{
string ghouse = Enum.GetName(tableName.GetType(), tableName);
}
w.Stop();
Console.WriteLine("I time = " + w.ElapsedTicks);
w.Reset();
w.Start();
for (int i = 0; i < 10000; i++)
{
string ghouse = tableName.ToString();
}
w.Stop();
Console.WriteLine("II time = " + w.ElapsedTicks);
Output
I time = 24606
II time = 38881
w.Start();
for (int i = 0; i < 10000; i++)
{
string ghouse = Enum.GetName(tableName.GetType(), tableName);
}
w.Stop();
Console.WriteLine("I time = " + w.ElapsedTicks);
w.Reset();
w.Start();
for (int i = 0; i < 10000; i++)
{
string ghouse = tableName.ToString();
}
w.Stop();
Console.WriteLine("II time = " + w.ElapsedTicks);
Output
I time = 24606
II time = 38881
Comments
Post a Comment