Skip to content

Instantly share code, notes, and snippets.

@bbarry
Created April 1, 2015 03:59
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 bbarry/8d043d04a4c170a64b55 to your computer and use it in GitHub Desktop.
Save bbarry/8d043d04a4c170a64b55 to your computer and use it in GitHub Desktop.
/*
output (cpu: i7 920)
Starting Benchmark
Running iteration: 1000/1000
Running 1000000 sub-iterations - Time Taken: 00:00:00.0043953
Running 1000000 sub-iterations - Time Taken: 00:00:00.0037585
Test 1
Average Time: 00:00:00.0043999
Invalid Operations: 750007614 (75.001 %)
Test 2
Average Time: 00:00:00.0037506
Invalid Operations: 750007614 (75.001 %)
Finished Benchmark
Press any key to exit...
*/
//...
static long RunLoop1(int[] indexArgs, int[] sizeArgs, ref long invalidOperationCount)
{
Stopwatch sw = new Stopwatch();
Console.Write("Running {0} sub-iterations", LoopCount);
sw.Start();
long startTickCount = sw.ElapsedTicks;
for (int i = 0; i < LoopCount; i++)
{
var index = indexArgs[i];
var size = sizeArgs[i];
invalidOperationCount += (index < 0 || index >= size) ? 1 : 0;
}
sw.Stop();
long stopTickCount = sw.ElapsedTicks;
long elapsedTickCount = stopTickCount - startTickCount;
Console.WriteLine(" - Time Taken: {0}", new TimeSpan(elapsedTickCount));
return elapsedTickCount;
}
static long RunLoop2(int[] indexArgs, int[] sizeArgs, ref long invalidOperationCount)
{
Stopwatch sw = new Stopwatch();
Console.Write("Running {0} sub-iterations", LoopCount);
sw.Start();
long startTickCount = sw.ElapsedTicks;
for (int i = 0; i < LoopCount; i++)
{
var index = indexArgs[i];
var size = sizeArgs[i];
invalidOperationCount += ((uint)(index) >= (uint)(size)) ? 1 : 0;
}
sw.Stop();
long stopTickCount = sw.ElapsedTicks;
long elapsedTickCount = stopTickCount - startTickCount;
Console.WriteLine(" - Time Taken: {0}", new TimeSpan(elapsedTickCount));
return elapsedTickCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment