Created
July 24, 2019 08:32
-
-
Save hexagit/7ced0c064a3b15166411de483753a66c to your computer and use it in GitHub Desktop.
Enum.GetHashCodeの負荷を確認するCS
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
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