Skip to content

Instantly share code, notes, and snippets.

@badamczewski
Created February 4, 2021 11:48
Show Gist options
  • Select an option

  • Save badamczewski/c62492b000ef68fa73eb1db3e2eefe3c to your computer and use it in GitHub Desktop.

Select an option

Save badamczewski/c62492b000ef68fa73eb1db3e2eefe3c to your computer and use it in GitHub Desktop.
[DisassemblyDiagnoser(maxDepth:2, printSource:true)]
public class Bench5
{
public int[] a = new int[1024];
public int size = 1024;
[GlobalSetup]
public void Setup()
{
//for (int i = 0; i < size; i++)
// a[i] = i;
}
[Benchmark(Baseline = true)]
[Arguments(10,10)]
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
public void Loop_Size_Global(int x, int y)
{
for (int i = 0; i < size; i++)
a[i] = x + y;
}
[Benchmark]
[Arguments(10, 10)]
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
public void Loop_Size_Local(int x, int y)
{
int sizeLocal = size;
for (int i = 0; i < 1024; i++)
a[i] = x + y;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment