CSharp · Console
using System;
using KGySoft.CoreLibraries;
using KGySoft.Diagnostics;
/*
NOTE: This is a .NET Framework test. System.Enum performance has been radically improved in .NET Core and above
See this link for more enum performance tests in .NET 5.0: https://dotnetfiddle.net/xNTnLE
*/
public class Example
{
public static void Main(string[] args)
{
new PerformanceTest
{
TestName = "System.Enum vs. KGySoft.CoreLibraries.Enum<TEnum>",
Iterations = 100000,
Repeat = 2,
CpuAffinity = null // disabling just for .NET Fiddle
}
.AddCase(() => ConsoleColor.Black.ToString(), "Enum.ToString")
.AddCase(() => Enum<ConsoleColor>.ToString(ConsoleColor.Black), "Enum<TEnum>.ToString")
.DoTest()
.DumpResults(Console.Out);
}
}