Skip to content

Instantly share code, notes, and snippets.

@hexagit
Created July 24, 2019 08:32
Show Gist options
  • Save hexagit/7ced0c064a3b15166411de483753a66c to your computer and use it in GitHub Desktop.
Save hexagit/7ced0c064a3b15166411de483753a66c to your computer and use it in GitHub Desktop.
Enum.GetHashCodeの負荷を確認するCS
enum TestEnum : int {
Test0 = 1,
}
static void Main(string[] args)
{
// 500万回GetHashCodeを呼ぶ
const int MaxCount = 5000000;
// EnumTest
{
var sum = 0;
var sw = new System.Diagnostics.Stopwatch();
for (var index = 0; index < MaxCount; ++index)
{
sw.Start();
sum += TestEnum.Test0.GetHashCode();
sw.Stop();
}
System.Diagnostics.Trace.WriteLine($"EnumTest = {sw.ElapsedMilliseconds}ミリ秒, Sum = {sum}");
}
// IntTest
{
var sum = 0;
int value0 = 1;
var sw = new System.Diagnostics.Stopwatch();
for (var index = 0; index < MaxCount; ++index)
{
sw.Start();
sum += value0.GetHashCode();
sw.Stop();
}
System.Diagnostics.Trace.WriteLine($"IntTest = {sw.ElapsedMilliseconds}ミリ秒, Sum = {sum}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment