Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.