Created
February 28, 2017 08:31
-
-
Save anonymous/edca38b045d5a6d420766f79096cc6d8 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.Running; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
BenchmarkRunner.Run<Test>(); | |
} | |
} | |
public class Test | |
{ | |
public int A { get; set; } | |
public int B { get; set; } | |
public int C { get; set; } | |
[Benchmark(Baseline = true)] | |
public void AddHalfRange() | |
{ | |
var a = A; | |
var b = B; | |
var c = C; | |
c += a + (b - a) / 2; | |
C = c; | |
} | |
[Benchmark] | |
public void AddHalf() | |
{ | |
var a = A; | |
var b = B; | |
var c = C; | |
c += (int)(((uint)b + (uint)a) / 2); | |
C = c; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment