Last active
February 14, 2017 17:19
-
-
Save mattwarren/790b028796a58de0556a to your computer and use it in GitHub Desktop.
Benchmark of the costs of different ways of creating GUIDs
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
// From https://twitter.com/aarnott/status/701653964823990273 | |
public class Framework_Guid | |
{ | |
[Benchmark(Baseline = true)] | |
public Guid CtorWithHexValues() | |
{ | |
// creates a Guid that corresponds to "12345678-000b-000c-0001-020304050607". | |
return new Guid(0x12345678, 0xb, 0xc, 0, 1, 2, 3, 4, 5, 6, 7); | |
} | |
[Benchmark] | |
public Guid CtorWithString() | |
{ | |
return new Guid("{12345678-000b-000c-0001-020304050607}"); | |
} | |
} |
Sorry, I wasn't clear, you need to use BenchmarkDotNet, see https://github.com/perfDotNet/BenchmarkDotNet/ and https://www.nuget.org/packages/BenchmarkDotNet/
Cool, thanks. And I see you mentioned it in your Tweet. Sorry I missed that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not familiar with
[Benchmark]
attributes. What do I need to run them?