Skip to content

Instantly share code, notes, and snippets.

@LeeCampbell
Last active December 1, 2016 08:46
Show Gist options
  • Save LeeCampbell/9e9f7fb39b6c19a181c1e12bb575bfe4 to your computer and use it in GitHub Desktop.
Save LeeCampbell/9e9f7fb39b6c19a181c1e12bb575bfe4 to your computer and use it in GitHub Desktop.
Benchmark via gist sample
using System.Threading;
using BenchmarkDotNet.Attributes;
public class IncrementBenchmarks
{
private int _intValue;
private long _longValue;
[Setup]
public void Setup()
{
_intValue = 0;
_longValue = 0;
}
[Benchmark(Baseline = true)]
public int Increment32BitInteger()
{
return ++_intValue;
}
[Benchmark]
public long Increment64BitInteger()
{
return ++_longValue;
}
[Benchmark]
public long InterlockedIncrement32BitInteger()
{
return Interlocked.Increment(ref _intValue);
}
[Benchmark]
public long InterlockedIncrement64BitInteger()
{
return Interlocked.Increment(ref _longValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment