Performance: Select Highlights
While ananoid is more concerned with correctness and ergonomics, it nevertheless trie to maintain good performance. To that end, the repository includes a project which benchmarks several different aspects of the library, via the excellent Benchmark.NET library. As with all performance assessments, the results should be taken with a grain of salt, and are not necessarily indicative of every possible situation wherein ananoid might be used. Consumers should always profile their own use cases, and not rely solely on the results presented here. That being said, what follows are some important highlights.
Highlight: Ananoid vs NanoidNet vs Guid
Perhaps the most intersting results are those comparing ananoid to the popular NanoidNet library (and to the
built-in Guid type, as a baseline). Each candidate is invoked numerous times, using its respective default settings,
to track the general throughput, memory usage, and other relevant metrics.
Method |
Mean |
Error |
StdDev |
Ratio |
RatioSD |
Gen0 |
Allocated |
Alloc Ratio |
|---|---|---|---|---|---|---|---|---|
Guid |
63.66 ns |
0.478 ns |
0.424 ns |
1.00 |
0.01 |
0.0102 |
96 B |
1.00 |
NanoidNet |
125.05 ns |
2.032 ns |
1.586 ns |
1.96 |
0.03 |
0.0212 |
200 B |
2.08 |
Ananoid |
86.77 ns |
0.361 ns |
0.320 ns |
1.36 |
0.01 |
0.0136 |
128 B |
1.33 |
Highlight: Structs vs Functions
Ananoid is designed to have both a low-level API, working in terms of primitives. And a high-level API, wherein everything is driven by bespoke types. It is important to note how the high-level API improves correctness with only minimal performance overhead, as shown in the following comparison of the two approaches.
Method |
Mean |
Error |
StdDev |
Ratio |
Gen0 |
Allocated |
Alloc Ratio |
|---|---|---|---|---|---|---|---|
Function |
89.31 ns |
0.504 ns |
0.447 ns |
1.00 |
0.0136 |
128 B |
1.00 |
Struct |
87.22 ns |
0.461 ns |
0.409 ns |
0.98 |
0.0136 |
128 B |
1.00 |
Interpreting Statistics
The above tables include a number of different metrics, which make use of the following terms:
- Mean: Arithmetic mean of all measurements
- Error: Half of 99.9% confidence interval
- StdDev: Standard deviation of all measurements
- Ratio: Mean of the ratio distribution ([Current]/[Baseline])
- RatioSD: Standard deviation of the ratio distribution ([Current]/[Baseline])
- Gen0: GC Generation 0 collects per 1000 operations
- Allocated: Allocated memory per single operation (managed only, inclusive, 1KB = 1024B)
- Alloc Ratio: Allocated memory ratio distribution ([Current]/[Baseline])
- 1 ns: 1 Nanosecond (0.000000001 sec)
System Setup
The benchmarks were run under the following specifications:
- BenchmarkDotNet: v0.15.8
- Operating System: Windows 11 (10.0.26200.8037/25H2/2025Update/HudsonValley2)
- Computer: 13th Gen Intel Core i7-1360P 2.20GHz, 1 CPU, 16 logical and 12 physical cores
- .NET SDK: 10.0.104
- GC Strategy: Concurrent Workstation
- Run Strategy: Throughput
-
Hardware Intrinsics:
- AVX2+BMI1+BMI2+F16C+FMA+LZCNT+MOVBE
- AVX
- SSE3+SSSE3+SSE4.1+SSE4.2+POPCNT
- X86Base+SSE+SSE2
- AES+PCLMUL
- AvxVnni
- SERIALIZE VectorSize=256
- [Host]: .NET 10.0.4 (10.0.4, 10.0.426.12010), X64 RyuJIT x86-64-v3 RELEASE
- Job-CEIKLR: .NET 10.0.4 (10.0.4, 10.0.426.12010), X64 RyuJIT x86-64-v3
Further Reading
- Project: BenchmarkDotNet
- Project: NanoidNet
- How-To: Create a Default NanoId
- How-To: Work with NanoId strings
Copyright
The library is available under the Mozilla Public License, Version 2.0. For more information see the project's License file.
ananoid