Last active
June 9, 2016 12:27
-
-
Save NickCraver/634610b6606a205ff8119890338da735 to your computer and use it in GitHub Desktop.
TimeSpan.FromSeconds() benchmark
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; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Configs; | |
using BenchmarkDotNet.Diagnostics.Windows; | |
using BenchmarkDotNet.Running; | |
namespace Benchmarks | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
BenchmarkRunner.Run<TimeSpanTests>(); | |
} | |
} | |
class Config : ManualConfig | |
{ | |
public Config() | |
{ | |
Add(new MemoryDiagnoser()); | |
Add(new InliningDiagnoser()); | |
} | |
} | |
[Config(typeof(Config))] | |
public class TimeSpanTests | |
{ | |
[Benchmark] | |
public TimeSpan GetTimeSpan() => TimeSpan.FromSeconds(30); | |
[Benchmark] | |
public TimeSpan GetTimeSpanConstructor() => new TimeSpan(30 * 600000000L); | |
[Benchmark] | |
public TimeSpan GetExtension() => 30.Seconds(); | |
[Benchmark] | |
public int GetMs() => 30 * 1000; | |
} | |
public static class TimeExtensions | |
{ | |
public static TimeSpan Seconds(this int i) => new TimeSpan(i * 600000000L); | |
} | |
} |
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
BenchmarkDotNet=v0.9.7.0 | |
OS=Microsoft Windows NT 6.2.9200.0 | |
Processor=Intel(R) Core(TM) i7-4960HQ CPU 2.60GHz, ProcessorCount=4 | |
Frequency=10000000 ticks, Resolution=100.0000 ns, Timer=UNKNOWN | |
HostCLR=MS.NET 4.0.30319.42000, Arch=32-bit RELEASE | |
JitModules=clrjit-v4.6.1055.0 | |
Type=TimeSpanTests Mode=Throughput | |
Method | Median | StdDev | Gen 0 | Gen 1 | Gen 2 | Bytes Allocated/Op | | |
----------------------- |----------- |---------- |------ |------ |------ |------------------- | | |
GetTimeSpan | 10.0114 ns | 0.3380 ns | - | - | - | 0.00 | | |
GetTimeSpanConstructor | 0.0000 ns | 0.0766 ns | - | - | - | 0.00 | | |
GetExtension | 0.0000 ns | 0.0565 ns | - | - | - | 0.00 | | |
GetMs | 0.5195 ns | 0.1295 ns | - | - | - | 0.00 | | |
// * Diagnostic Output - MemoryDiagnoser * | |
// * Diagnostic Output - InliningDiagnoser * | |
-------------------- | |
-------------------- | |
TimeSpanTests_GetTimeSpan_Mode-Throughput_Platform-Host_Jit-Host_Framework-Host_Runtime-Host_WarmupCount-Auto_TargetCount-Auto_LaunchCount-Auto_IterationTime-Auto_Affinity-Auto | |
-------------------- | |
Inliner: BenchmarkDotNet.Autogenerated.Program..ctor - instance void () | |
Inlinee: Benchmarks.TimeSpanTests..ctor - instance void () | |
-------------------- | |
Inliner: Benchmarks.TimeSpanTests..ctor - instance void () | |
Inlinee: System.Object..ctor - instance void () | |
-------------------- | |
Inliner: Benchmarks.TimeSpanTests.GetTimeSpan - instance value class System.TimeSpan () | |
Inlinee: System.TimeSpan.FromSeconds - value class System.TimeSpan (float64) | |
-------------------- | |
-------------------- | |
TimeSpanTests_GetTimeSpanConstructor_Mode-Throughput_Platform-Host_Jit-Host_Framework-Host_Runtime-Host_WarmupCount-Auto_TargetCount-Auto_LaunchCount-Auto_IterationTime-Auto_Affinity-Auto | |
-------------------- | |
Inliner: BenchmarkDotNet.Autogenerated.Program..ctor - instance void () | |
Inlinee: Benchmarks.TimeSpanTests..ctor - instance void () | |
-------------------- | |
Inliner: Benchmarks.TimeSpanTests..ctor - instance void () | |
Inlinee: System.Object..ctor - instance void () | |
-------------------- | |
Inliner: Benchmarks.TimeSpanTests.GetTimeSpanConstructor - instance value class System.TimeSpan () | |
Inlinee: System.TimeSpan..ctor - instance void (int64) | |
-------------------- | |
-------------------- | |
TimeSpanTests_GetExtension_Mode-Throughput_Platform-Host_Jit-Host_Framework-Host_Runtime-Host_WarmupCount-Auto_TargetCount-Auto_LaunchCount-Auto_IterationTime-Auto_Affinity-Auto | |
-------------------- | |
Inliner: BenchmarkDotNet.Autogenerated.Program..ctor - instance void () | |
Inlinee: Benchmarks.TimeSpanTests..ctor - instance void () | |
-------------------- | |
Inliner: Benchmarks.TimeSpanTests..ctor - instance void () | |
Inlinee: System.Object..ctor - instance void () | |
-------------------- | |
Inliner: Benchmarks.TimeSpanTests.GetExtension - instance value class System.TimeSpan () | |
Inlinee: Benchmarks.TimeExtensions.Seconds - value class System.TimeSpan (int32) | |
-------------------- | |
-------------------- | |
TimeSpanTests_GetMs_Mode-Throughput_Platform-Host_Jit-Host_Framework-Host_Runtime-Host_WarmupCount-Auto_TargetCount-Auto_LaunchCount-Auto_IterationTime-Auto_Affinity-Auto | |
-------------------- | |
Inliner: BenchmarkDotNet.Autogenerated.Program..ctor - instance void () | |
Inlinee: Benchmarks.TimeSpanTests..ctor - instance void () | |
-------------------- | |
Inliner: Benchmarks.TimeSpanTests..ctor - instance void () | |
Inlinee: System.Object..ctor - instance void () | |
-------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment