FastGuid 1.0.6
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package FastGuid --version 1.0.6
NuGet\Install-Package FastGuid -Version 1.0.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FastGuid" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FastGuid --version 1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FastGuid, 1.0.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FastGuid as a Cake Addin #addin nuget:?package=FastGuid&version=1.0.6 // Install FastGuid as a Cake Tool #tool nuget:?package=FastGuid&version=1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FastGuid
by Stan Drapkin
10 times faster than Guid.NewGuid()
Static APIs
Guid FastGuid.NewGuid()
- returns a cryptographically random GUID.
- ~10x faster than Guid.NewGuid().
FastGuid.Fill(Span<byte> data)
- Fills a span with cryptographically strong random bytes.
- ~5x faster for <512 bytes, otherwise calls RandomNumberGenerator.Fill()
Usage
Replace all calls to Guid.NewGuid()
with FastGuid.NewGuid()
..from this:
Guid guid = Guid.NewGuid(); // your current code
..to this:
// using SecurityDriven;
Guid guid = FastGuid.NewGuid(); // 10x faster
- Thread-safe
- 128 bits of cryptographically-strong randomness
Switch from this:
Span<byte> key = stackalloc byte[32];
RandomNumberGenerator.Fill(key); // 145 nanoseconds
..to this:
Span<byte> key = stackalloc byte[32];
FastGuid.Fill(key); // 25 nanoseconds
Benchmark:
public class Bench
{
[Benchmark(Baseline = true)]
public void FastGuid_NewGuid() // 12 calls
{
FastGuid.NewGuid(); FastGuid.NewGuid(); FastGuid.NewGuid(); FastGuid.NewGuid();
FastGuid.NewGuid(); FastGuid.NewGuid(); FastGuid.NewGuid(); FastGuid.NewGuid();
FastGuid.NewGuid(); FastGuid.NewGuid(); FastGuid.NewGuid(); FastGuid.NewGuid();
}
[Benchmark]
public void Guid_NewGuid() // 12 calls
{
Guid.NewGuid(); Guid.NewGuid(); Guid.NewGuid(); Guid.NewGuid();
Guid.NewGuid(); Guid.NewGuid(); Guid.NewGuid(); Guid.NewGuid();
Guid.NewGuid(); Guid.NewGuid(); Guid.NewGuid(); Guid.NewGuid();
}
}//class Bench
BenchmarkDotNet=v0.13.2, OS=Windows 10 (10.0.19045.2364)
Intel Core i7-10510U CPU 1.80GHz, 1 CPU, 8 logical and 4 physical cores
.NET SDK=7.0.101
[Host] : .NET 7.0.1 (7.0.122.56804), X64 RyuJIT AVX2
Method | Mean | Error | StdDev | Ratio |
---|---|---|---|---|
FastGuid_NewGuid | 116.6 ns | 2.26 ns | 5.19 ns | 1.00 |
Guid_NewGuid | 1,215.9 ns | 23.85 ns | 45.96 ns | 10.39 |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net5.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Performance improvements.
~10x faster than Guid.NewGuid().
Performance-tested on .NET 8, 7, 6, and 5.
New FastGuid.Fill() method - see README.