Skip to content

Instantly share code, notes, and snippets.

@vcaraulean
Last active July 11, 2016 21:43
Show Gist options
  • Save vcaraulean/6a0e3201ea7889e06bd35391bba0d521 to your computer and use it in GitHub Desktop.
Save vcaraulean/6a0e3201ea7889e06bd35391bba0d521 to your computer and use it in GitHub Desktop.
Benchmarking NLog's TimeSource implementations
// Required nuget packages:
// - NLog
// - BenchmarkDotNet
namespace BenchmarkNlogTimeSources
{
public class TimeSourceBenchmark
{
private readonly TimeSource _fastLocalTimeSource = new FastLocalTimeSource();
private readonly TimeSource _fastUtcTimeSource = new FastUtcTimeSource();
private readonly TimeSource _accurateLocalTimeSource = new AccurateLocalTimeSource();
private readonly TimeSource _accurateUtcTimeSource = new AccurateUtcTimeSource();
[Benchmark]
public DateTime FastLocal()
{
return _fastLocalTimeSource.Time;
}
[Benchmark]
public DateTime FastUtc()
{
return _fastUtcTimeSource.Time;
}
[Benchmark]
public DateTime AccurateLocal()
{
return _accurateLocalTimeSource.Time;
}
[Benchmark]
public DateTime AccurateUtc()
{
return _accurateUtcTimeSource.Time;
}
}
class Program
{
static void Main(string[] args)
{
BenchmarkRunner.Run<TimeSourceBenchmark>();
}
}
}
Host Process Environment Information:
BenchmarkDotNet=v0.9.8.0
OS=Microsoft Windows NT 6.2.9200.0
Processor=Intel(R) Core(TM) i7-6650U CPU 2.20GHz, ProcessorCount=4
Frequency=2156245 ticks, Resolution=463.7692 ns, Timer=TSC
CLR=MS.NET 4.0.30319.42000, Arch=32-bit RELEASE
GC=Concurrent Workstation
JitModules=clrjit-v4.6.1080.0

Type=TimeSourceBenchmark  Mode=Throughput  GarbageCollection=Concurrent Workstation  
    Method |      Median |     StdDev |

-------------- |------------ |----------- | FastLocal | 5.7752 ns | 0.3450 ns | FastUtc | 5.8330 ns | 0.4939 ns | AccurateLocal | 784.4354 ns | 61.6136 ns | AccurateUtc | 7.0547 ns | 0.3934 ns |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment