Created
December 19, 2021 18:38
-
-
Save BurstX/f64734c118e48087c516cf5fa7e397df to your computer and use it in GitHub Desktop.
This file contains 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
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Jobs; | |
using BenchmarkDotNet.Running; | |
[SimpleJob(RuntimeMoniker.Net60)] | |
[MinColumn, MaxColumn] | |
public class Test | |
{ | |
public static int A = 0; | |
private const int Max = 10_000; | |
[Benchmark] | |
public void MethodSingleElement() | |
{ | |
A = 0; | |
var arr = Enumerable.Range(0, Max).ToArray(); | |
for (long i =0; i < Max; i++) | |
{ | |
unchecked | |
{ | |
A += arr[i]; | |
} | |
} | |
} | |
[Benchmark] | |
public void MethodDiv() | |
{ | |
A = 0; | |
var arr = Enumerable.Range(0, Max).ToArray(); | |
for (long i = 0; i < Max; i += 4) | |
{ | |
unchecked | |
{ | |
A += arr[i]; | |
A += arr[i+1]; | |
A += arr[i+2]; | |
A += arr[i+3]; | |
} | |
} | |
} | |
} | |
public static class Program | |
{ | |
public static void Main(string[] arr) | |
{ | |
var summary = BenchmarkRunner.Run<Test>(); | |
//foreach(var s in summary) | |
//{ | |
// Console.WriteLine(s.ToString()); | |
//} | |
//Console.WriteLine(Test.A); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment