Created
January 8, 2015 02:55
-
-
Save JeffreyZhao/8eebb8927a4557ace03a to your computer and use it in GitHub Desktop.
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
[MethodImpl(MethodImplOptions.NoInlining)] | |
static object UseBox(int num) | |
{ | |
return num; | |
} | |
private class IntWrapper | |
{ | |
public int Num; | |
} | |
[MethodImpl(MethodImplOptions.NoInlining)] | |
static object UseWrapper(int num) | |
{ | |
return new IntWrapper { Num = num }; | |
} | |
static void Main() | |
{ | |
CodeTimer.Initialize(); | |
CodeTimer.Time("Box", 10000000, () => UseBox(10)); | |
CodeTimer.Time("Wrapper", 10000000, () => UseWrapper(10)); | |
} | |
/* | |
Box | |
Time Elapsed: 1,274ms | |
CPU Cycles: 3,047,706,156 | |
Gen 0: 457 | |
Gen 1: 0 | |
Gen 2: 0 | |
Wrapper | |
Time Elapsed: 1,056ms | |
CPU Cycles: 2,527,914,244 | |
Gen 0: 457 | |
Gen 1: 0 | |
Gen 2: 0 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment