Last active
December 1, 2016 08:46
-
-
Save LeeCampbell/9e9f7fb39b6c19a181c1e12bb575bfe4 to your computer and use it in GitHub Desktop.
Benchmark via gist sample
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 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