Skip to content

Instantly share code, notes, and snippets.

@MeilCli
Created June 26, 2018 22:55
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 MeilCli/f02c9616ec04fde202d9bc91368fb099 to your computer and use it in GitHub Desktop.
Save MeilCli/f02c9616ec04fde202d9bc91368fb099 to your computer and use it in GitHub Desktop.
Type.GetTypeベンチマーク
BenchmarkDotNet=v0.10.14, OS=Windows 10.0.16299.492 (1709/FallCreatorsUpdate/Redstone3)
Intel Core i7-6700 CPU 3.40GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
Frequency=3328122 Hz, Resolution=300.4698 ns, Timer=TSC
.NET Core SDK=2.1.300
  [Host] : .NET Core 2.1.0 (CoreCLR 4.6.26515.07, CoreFX 4.6.26515.06), 64bit RyuJIT
  Core   : .NET Core 2.1.0 (CoreCLR 4.6.26515.07, CoreFX 4.6.26515.06), 64bit RyuJIT

Job=Core  Runtime=Core  
Method Mean Error StdDev Min Max Gen 0 Allocated
GenericsTypeFullNameWithAssemblyDetail 10.045 us 0.0595 us 0.0497 us 9.932 us 10.120 us 0.0763 360 B
GenericsTypeFullNameWithAssembly 8.205 us 0.1504 us 0.1407 us 8.043 us 8.468 us 0.0763 360 B
GenericsTypeFullName 5.661 us 0.0225 us 0.0163 us 5.638 us 5.693 us 0.0839 360 B
TypeFullNameWithAssemblyDetail 2.950 us 0.0550 us 0.0514 us 2.878 us 3.071 us - 0 B
TypeFullNameWithAssembly 2.486 us 0.0197 us 0.0174 us 2.450 us 2.524 us - 0 B
TypeFullName 1.810 us 0.0201 us 0.0178 us 1.785 us 1.830 us - 0 B
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Columns;
using BenchmarkDotNet.Attributes.Jobs;
using System;
namespace Bench
{
[CoreJob]
[MeanColumn, MinColumn, MaxColumn]
[MemoryDiagnoser]
public class TypeBench
{
[Benchmark]
public Type GenericsTypeFullNameWithAssemblyDetail()
{
return Type.GetType(@"System.Collections.Generic.Dictionary`2[
[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],
[System.Collections.Generic.List`1[
[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]
], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]],
System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e");
}
[Benchmark]
public Type GenericsTypeFullNameWithAssembly()
{
return Type.GetType(@"System.Collections.Generic.Dictionary`2[
[System.String, System.Private.CoreLib],
[System.Collections.Generic.List`1[[System.String, System.Private.CoreLib]], System.Private.CoreLib]],
System.Private.CoreLib");
}
[Benchmark]
public Type GenericsTypeFullName()
{
return Type.GetType(@"System.Collections.Generic.Dictionary`2[[System.String],[System.Collections.Generic.List`1[[System.String]]]]");
}
[Benchmark]
public Type TypeFullNameWithAssemblyDetail()
{
return Type.GetType("System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e");
}
[Benchmark]
public Type TypeFullNameWithAssembly()
{
return Type.GetType("System.String, System.Private.CoreLib");
}
[Benchmark]
public Type TypeFullName()
{
return Type.GetType("System.String");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment