Closed
Description
DateTime.UtcNow
and DateTimeOffset.UtcNow
are 2.5x slower compared to 2.2
[Benchmark]
public DateTimeOffset GetUtcNow() => DateTimeOffset.UtcNow;
[Benchmark]
public DateTime GetUtcNow() => DateTime.UtcNow;
Repro
git clone https://github.com/dotnet/performance.git
cd performance
# if you don't have cli installed and want python script to download the latest cli for you
py .\scripts\benchmarks_ci.py -f netcoreapp2.2 netcoreapp3.0 --filter *GetUtcNow*
# if you do
dotnet run -p .\src\benchmarks\micro\MicroBenchmarks.csproj -c Release -f netcoreapp2.2 --filter *GetUtcNow* --runtimes netcoreapp2.2 netcoreapp3.0 --join
BenchmarkDotNet=v0.11.3.1003-nightly, OS=Windows 10.0.18362
Intel Xeon CPU E5-1650 v4 3.60GHz, 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=3.0.100-preview8-013262
[Host] : .NET Core 2.2.6 (CoreCLR 4.6.27817.03, CoreFX 4.6.27818.02), 64bit RyuJIT
Job-BYJCMJ : .NET Core 2.2.6 (CoreCLR 4.6.27817.03, CoreFX 4.6.27818.02), 64bit RyuJIT
Job-JSSCYO : .NET Core 3.0.0-preview8-27916-02 (CoreCLR 4.700.19.36302, CoreFX 4.700.19.36514), 64bit RyuJIT
Type | Method | Toolchain | Mean |
---|---|---|---|
Perf_DateTime | GetUtcNow | netcoreapp2.2 | 25.12 ns |
Perf_DateTime | GetUtcNow | netcoreapp3.0 | 70.91 ns |
Perf_DateTimeOffset | GetUtcNow | netcoreapp2.2 | 38.19 ns |
Perf_DateTimeOffset | GetUtcNow | netcoreapp3.0 | 91.96 ns |
/cc @danmosemsft