Created
July 27, 2021 13:41
-
-
Save badamczewski/03a53c07dfbe013aa8b8ff99f49a208c 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