Last active
August 29, 2015 14:26
-
-
Save redknightlois/045d3022c2c28e1498e2 to your computer and use it in GitHub Desktop.
This file contains 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
[Task(platform: BenchmarkPlatform.X64, jitVersion: BenchmarkJitVersion.LegacyJit)] | |
[Task(platform: BenchmarkPlatform.X64, jitVersion: BenchmarkJitVersion.RyuJit)] | |
public class Jit_BoolToInt | |
{ | |
private bool first; | |
private bool second; | |
public Jit_BoolToInt() | |
{ | |
first = true; | |
second = false; | |
} | |
[Benchmark] | |
public int Framework() | |
{ | |
int sum = Convert.ToInt32(first); | |
sum += Convert.ToInt32(second); | |
return sum; | |
} | |
[Benchmark] | |
public int IfThenElse() | |
{ | |
int sum = first ? 1 : 0; | |
sum += second ? 1 : 0; | |
return sum; | |
} | |
[Benchmark] | |
public int UnsafeConvert() | |
{ | |
unsafe | |
{ | |
bool v1 = first; | |
int sum = *(byte*)(&v1); | |
bool v2 = second; | |
sum += *(byte*)(&v2); | |
return sum; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment