Created
August 1, 2017 08:34
-
-
Save Liminiens/cef6d7c9dc68a4fed9a6502c4a24c751 to your computer and use it in GitHub Desktop.
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
Total time: 00:03:10 (190.47 sec) | |
// * Summary * | |
BenchmarkDotNet=v0.10.9, OS=Windows 10 Redstone 2 (10.0.15063) | |
Processor=Intel Core i5-4670 CPU 3.40GHz (Haswell), ProcessorCount=4 | |
Frequency=3320320 Hz, Resolution=301.1758 ns, Timer=TSC | |
[Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.2101.1 | |
DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.2101.1 | |
Method | Mean | Error | StdDev | | |
--------------------------- |---------:|----------:|----------:| | |
AsCast | 1.674 ns | 0.0337 ns | 0.0281 ns | | |
AsCastFromObject | 1.870 ns | 0.0667 ns | 0.0794 ns | | |
DirectCast | 1.859 ns | 0.0671 ns | 0.1308 ns | | |
DirectCastFromObject | 3.559 ns | 0.0997 ns | 0.1331 ns | | |
DirectCastFromObjectWithIs | 3.424 ns | 0.0981 ns | 0.1050 ns | | |
// * Hints * | |
Outliers | |
CastTest.AsCast: Default -> 2 outliers were removed | |
CastTest.AsCastFromObject: Default -> 1 outlier was removed | |
CastTest.DirectCastFromObject: Default -> 1 outlier was removed | |
CastTest.DirectCastFromObjectWithIs: Default -> 1 outlier was removed | |
// * Legends * | |
Mean : Arithmetic mean of all measurements | |
Error : Half of 99.9% confidence interval | |
StdDev : Standard deviation of all measurements | |
1 ns : 1 Nanosecond (0.000000001 sec) | |
// ***** BenchmarkRunner: End ***** |
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
public class A | |
{ } | |
public class B : A | |
{ } | |
public class CastTest | |
{ | |
[Benchmark] | |
public void AsCast() | |
{ | |
var b = new B(); | |
var a = b as A; | |
} | |
[Benchmark] | |
public void AsCastFromObject() | |
{ | |
object b = new B(); | |
var a = b as A; | |
} | |
[Benchmark] | |
public void DirectCast() | |
{ | |
var b = new B(); | |
var a = (A)b; | |
} | |
[Benchmark] | |
public void DirectCastFromObject() | |
{ | |
object b = new B(); | |
var a = (A)b; | |
} | |
[Benchmark] | |
public void DirectCastFromObjectWithIs() | |
{ | |
object b = new B(); | |
if (b is A) | |
{ | |
var a = (A)b; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment