Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@JeffreyZhao
Created January 8, 2015 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffreyZhao/8eebb8927a4557ace03a to your computer and use it in GitHub Desktop.
Save JeffreyZhao/8eebb8927a4557ace03a to your computer and use it in GitHub Desktop.
[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