Skip to content

Instantly share code, notes, and snippets.

@mattwarren
Last active February 14, 2017 17:19
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 mattwarren/790b028796a58de0556a to your computer and use it in GitHub Desktop.
Save mattwarren/790b028796a58de0556a to your computer and use it in GitHub Desktop.
Benchmark of the costs of different ways of creating GUIDs
// 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}");
}
}
@AArnott
Copy link

AArnott commented Feb 26, 2016

I'm not familiar with [Benchmark] attributes. What do I need to run them?

@mattwarren
Copy link
Author

Sorry, I wasn't clear, you need to use BenchmarkDotNet, see https://github.com/perfDotNet/BenchmarkDotNet/ and https://www.nuget.org/packages/BenchmarkDotNet/

@AArnott
Copy link

AArnott commented Feb 26, 2016

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