Skip to content

Instantly share code, notes, and snippets.

@ufcpp
Last active August 23, 2019 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ufcpp/07f05e81f29935c09bfc7270bb37b678 to your computer and use it in GitHub Desktop.
Save ufcpp/07f05e81f29935c09bfc7270bb37b678 to your computer and use it in GitHub Desktop.
やっぱ UtcNow の方が速いんだ。的なやつ。
Method Mean Error StdDev
DateTimeNowTicks 87.08 ns 1.0897 ns 1.0193 ns
DateTimeUtcNowTicks 68.06 ns 0.5209 ns 0.4617 ns
DateTimeOffsetNowTicks 114.62 ns 0.8232 ns 0.6874 ns
DateTimeOffsetUtcNowTicks 87.15 ns 0.2953 ns 0.2617 ns
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
public class TimeBenchmark
{
[Benchmark]
public long DateTimeNowTicks() => DateTime.Now.Ticks;
[Benchmark]
public long DateTimeUtcNowTicks() => DateTime.UtcNow.Ticks;
[Benchmark]
public long DateTimeOffsetNowTicks() => DateTimeOffset.Now.Ticks;
[Benchmark]
public long DateTimeOffsetUtcNowTicks() => DateTimeOffset.UtcNow.Ticks;
}
class Program
{
static void Main()
{
BenchmarkRunner.Run<TimeBenchmark>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment