Created
July 27, 2021 13:39
-
-
Save badamczewski/b1ce3cbc83aaf0cd35d2f9ba319cd21f 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
public class Bench92 | |
{ | |
public int[] _x = null; | |
[GlobalSetup] | |
public void Setup() | |
{ | |
_x = new int[10000]; | |
} | |
[Benchmark(Baseline = true)] | |
[MethodImpl(MethodImplOptions.NoInlining)] | |
[Arguments(0)] | |
public int A(int z) | |
{ | |
var x = _x; | |
try { _ = 1; } catch { } | |
for (int i = 0; i < x.Length; i++) | |
{ | |
x[i] = i + z; | |
z += x[i]; | |
} | |
return z; | |
} | |
[Benchmark()] | |
[MethodImpl(MethodImplOptions.NoInlining)] | |
[Arguments(0)] | |
public int B(int z) | |
{ | |
var x = _x; | |
try { _ = 1; } catch { } | |
var y = x; | |
var zz = z; | |
for (int i = 0; i < y.Length; i++) | |
{ | |
y[i] = i + zz; | |
zz += y[i]; | |
} | |
return zz; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment