Created
February 15, 2021 06:22
-
-
Save badamczewski/71fcc07b5e93fcfaff84f0df1be53f07 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
[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