Skip to content

Instantly share code, notes, and snippets.

Created February 28, 2017 08:31
Show Gist options
  • Save anonymous/edca38b045d5a6d420766f79096cc6d8 to your computer and use it in GitHub Desktop.
Save anonymous/edca38b045d5a6d420766f79096cc6d8 to your computer and use it in GitHub Desktop.
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