Home

Awesome

ksuid nuget

This is a dotnet implementation of Segment's K-Sortable Globally Unique Identifiers.

overview

installation

$ dotnet add package KsuidDotNet

how to use

Create a random KSUID:

string id = Ksuid.NewKsuid();

Console.WriteLine(id); // outputs 29faSiN1gPB6IzM74u6tMfTO02L

Creating a random KSUID string with the prefix c_:

string id = Ksuid.NewKsuid("c_");

Console.WriteLine(id); // outputs c_29faSiN1gPB6IzM74u6tMfTO02L

micro benchmarks

Benchmark results for KsuidDotNet and other KSUID libraries.


BenchmarkDotNet=v0.13.2, OS=Windows 11 (10.0.22621.1555)
13th Gen Intel Core i7-13700K, 1 CPU, 24 logical and 16 physical cores
.NET SDK=7.0.203
  [Host]     : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
  DefaultJob : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
MethodMeanErrorStdDevGen0Allocated
KsuidDotNet_NewKsuidToString194.8 ns0.46 ns0.43 ns0.005080 B
StructKsuid_RandomKsuidToString380.2 ns0.91 ns0.85 ns0.004880 B
DotKsuid_GenerateToString412.0 ns1.15 ns1.08 ns0.08391320 B
ksuid_GenerateToString1,884.6 ns7.08 ns6.27 ns0.49787824 B
KsuidDotNet_NewKsuid_WithStringPrefix196.5 ns0.37 ns0.35 ns0.005080 B
StructKsuid_RandomKsuidToStringWithStringPrefix387.2 ns0.50 ns0.44 ns0.0100160 B
DotKsuid_GenerateToStringWithStringPrefix421.5 ns1.05 ns0.98 ns0.08921400 B
ksuid_GenerateToStringWithStringPrefix1,881.8 ns8.95 ns7.94 ns0.50357904 B

license

This library is open-source software released under the MIT License.