Skip to content

Instantly share code, notes, and snippets.

@badamczewski
Created February 15, 2021 06:22
Show Gist options
  • Save badamczewski/71fcc07b5e93fcfaff84f0df1be53f07 to your computer and use it in GitHub Desktop.
Save badamczewski/71fcc07b5e93fcfaff84f0df1be53f07 to your computer and use it in GitHub Desktop.
[DisassemblyDiagnoser(maxDepth: 4)]
public class Bench5
{
public int[] array = null;
public int size = 500_000;
public int x = 10;
public int y = 10;
[GlobalSetup]
public void Setup()
{
Random rnd = new Random();
array = new int[100_000_000];
for (int i = 0; i < array.Length; i++)
array[i] = rnd.Next(0, 10);
}
[Benchmark]
public void SlowLoop()
{
var a = array;
for (int i = 0; i < 1000; i++)
a[i] += i + x;
}
[Benchmark]
public void FastLoop()
{
var a = array;
for (int i = 0; i < 1000; i++)
a[i] = a[i] + i + x;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment