From ca85669935fe4555f9ebda2d585058776b457f06 Mon Sep 17 00:00:00 2001 From: Michael Primeaux Date: Tue, 12 Nov 2024 11:36:32 -0600 Subject: [PATCH] DEBT: Documentation (#32) --- CHANGELOG/CHANGELOG-1.x.md | 14 +- README.md | 322 ++++++++++++++++++------------------- nanoid.go | 22 +-- x/crypto/prng/prng.go | 65 +++++++- x/crypto/prng/prng_test.go | 17 -- 5 files changed, 242 insertions(+), 198 deletions(-) diff --git a/CHANGELOG/CHANGELOG-1.x.md b/CHANGELOG/CHANGELOG-1.x.md index 26b49ae..bd634c7 100644 --- a/CHANGELOG/CHANGELOG-1.x.md +++ b/CHANGELOG/CHANGELOG-1.x.md @@ -15,6 +15,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### Security +--- +## [1.17.1] - 2024-NOV-12 + +### Added +### Changed +- **DEBT:** Refactored "godoc" comments to improve readability and clarity. +### Deprecated +### Removed +### Fixed +### Security + --- ## [1.17.0] - 2024-NOV-11 @@ -375,7 +386,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### Security -[Unreleased]: https://github.com/scriptures-social/platform/compare/v1.17.0..HEAD +[Unreleased]: https://github.com/scriptures-social/platform/compare/v1.17.1..HEAD +[1.17.1]: https://github.com/sixafter/nanoid/compare/v1.17.0...v1.17.1 [1.17.0]: https://github.com/sixafter/nanoid/compare/v1.16.1...v1.17.0 [1.16.1]: https://github.com/sixafter/nanoid/compare/v1.16.0...v1.16.1 [1.16.0]: https://github.com/sixafter/nanoid/compare/v1.15.0...v1.16.0 diff --git a/README.md b/README.md index 6460532..b2bbe96 100644 --- a/README.md +++ b/README.md @@ -261,168 +261,168 @@ go test -bench=. -benchmem -memprofile=mem.out -cpuprofile=cpu.out goos: darwin goarch: arm64 pkg: github.com/sixafter/nanoid -cpu: Apple M2 Ultra -BenchmarkNanoIDAllocations-24 10827518 104.6 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDAllocationsConcurrent-24 44067356 24.11 ns/op 24 B/op 1 allocs/op -BenchmarkGenerator_Read_DefaultLength-24 11847897 101.3 ns/op 24 B/op 1 allocs/op -BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_2-24 24025567 47.97 ns/op 8 B/op 1 allocs/op -BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_3-24 23834449 49.51 ns/op 8 B/op 1 allocs/op -BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_5-24 21935820 52.17 ns/op 8 B/op 1 allocs/op -BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_13-24 15598916 73.71 ns/op 16 B/op 1 allocs/op -BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_21-24 12269970 99.57 ns/op 24 B/op 1 allocs/op -BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_34-24 8378222 139.8 ns/op 48 B/op 1 allocs/op -BenchmarkGenerator_Read_ZeroLengthBuffer-24 643477209 1.833 ns/op 0 B/op 0 allocs/op -BenchmarkGenerator_Read_Concurrent/Concurrency_1-24 11262013 101.5 ns/op 24 B/op 1 allocs/op -BenchmarkGenerator_Read_Concurrent/Concurrency_2-24 21634225 55.88 ns/op 24 B/op 1 allocs/op -BenchmarkGenerator_Read_Concurrent/Concurrency_4-24 29086618 51.29 ns/op 24 B/op 1 allocs/op -BenchmarkGenerator_Read_Concurrent/Concurrency_8-24 40623742 29.63 ns/op 24 B/op 1 allocs/op -BenchmarkGenerator_Read_Concurrent/Concurrency_16-24 61002217 30.19 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen8-24 20715415 57.10 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen16-24 14955025 79.34 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen21-24 12279360 97.13 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen32-24 9492841 126.5 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen64-24 5610008 213.4 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen128-24 3108288 384.6 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen8-24 21041617 57.57 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen16-24 14756728 80.05 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen21-24 12446965 96.60 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen32-24 9663090 128.9 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen64-24 5370190 218.7 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen128-24 3104888 384.8 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen8-24 20816858 57.97 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen16-24 14801596 80.68 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen21-24 12056110 97.86 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen32-24 9495126 124.8 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen64-24 5546528 212.5 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen128-24 3147789 384.0 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen8-24 20705972 57.19 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen16-24 14748634 79.16 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen21-24 12383686 98.82 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen32-24 9345542 125.9 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen64-24 5227130 269.2 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen128-24 2709976 417.3 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen8-24 15063817 76.47 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen16-24 9674256 120.7 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen21-24 8037175 147.0 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen32-24 5904072 199.5 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen64-24 3332470 367.5 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen128-24 1737326 664.3 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen8-24 15536979 78.73 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen16-24 9345562 127.8 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen21-24 7986922 156.2 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen32-24 5588406 205.6 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen64-24 3380896 368.3 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen128-24 1793653 664.3 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen8-24 15461583 79.51 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen16-24 9352959 126.1 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen21-24 7632367 148.3 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen32-24 5662828 211.7 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen64-24 3163326 372.6 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen128-24 1719470 692.0 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen8-24 15438170 76.58 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen16-24 9705403 126.2 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen21-24 7993968 147.8 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen32-24 5979666 203.7 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen64-24 3246212 363.7 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen128-24 1789210 672.4 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen8-24 121349466 10.56 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen16-24 74708942 15.09 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen21-24 58505428 19.06 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen32-24 48815461 25.62 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen64-24 27255820 42.41 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen128-24 16345488 74.82 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen8-24 100000000 10.15 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen16-24 78140683 13.96 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen21-24 60587575 19.10 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen32-24 50252307 24.57 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen64-24 27003231 40.80 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen128-24 16524638 73.20 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen8-24 127892064 9.683 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen16-24 94048568 13.11 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen21-24 64258606 17.34 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen32-24 51897687 22.83 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen64-24 29772888 40.79 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen128-24 16770325 69.18 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen8-24 136429317 9.342 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen16-24 83319828 12.83 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen21-24 66990139 18.20 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen32-24 49283337 23.55 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen64-24 30812617 39.21 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen128-24 17114200 70.27 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen8-24 73182445 15.25 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen16-24 42446697 28.16 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen21-24 33360979 34.14 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen32-24 24449212 45.99 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen64-24 13794450 88.00 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen128-24 7435483 157.0 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen8-24 75993856 14.71 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen16-24 44642094 26.09 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen21-24 34424395 34.33 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen32-24 25146447 45.21 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen64-24 13921240 85.48 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen128-24 7565599 156.6 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen8-24 75665024 14.61 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen16-24 46223847 27.86 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen21-24 33996219 34.00 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen32-24 26041689 46.56 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen64-24 14382057 86.23 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen128-24 7704223 162.4 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen8-24 74564844 15.65 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen16-24 46940014 25.34 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen21-24 33220176 34.68 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen32-24 26996548 46.71 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen64-24 14012982 89.21 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen128-24 7678606 155.9 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen8-24 19627298 60.10 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen16-24 14579775 81.96 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen21-24 11201199 98.05 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen32-24 9198715 126.0 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen64-24 5539738 219.1 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen128-24 3102500 386.5 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen8-24 19726945 58.64 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen16-24 14528738 81.44 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen21-24 11859025 99.33 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen32-24 9354871 128.0 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen64-24 5454200 218.2 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen128-24 3035320 390.7 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen8-24 19795814 59.80 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen16-24 14687432 79.53 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen21-24 12302660 96.29 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen32-24 9485805 127.7 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen64-24 5519390 213.5 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen128-24 3087526 386.2 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen8-24 19896495 58.97 ns/op 8 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen16-24 14839662 80.72 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen21-24 12053421 98.48 ns/op 24 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen32-24 9226418 131.5 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen64-24 5591241 211.4 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen128-24 3081849 383.0 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen8-24 15504409 77.82 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen16-24 9529544 123.5 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen21-24 7968878 148.6 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen32-24 5883114 201.6 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen64-24 3263871 363.7 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen128-24 1773298 686.8 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen8-24 15515886 77.89 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen16-24 9515356 123.8 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen21-24 8041390 155.3 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen32-24 5529211 206.0 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen64-24 3244819 377.3 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen128-24 1729305 690.8 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen8-24 15179576 79.85 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen16-24 9526300 126.5 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen21-24 7690760 154.2 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen32-24 5752617 209.7 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen64-24 3052999 391.2 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen128-24 1636466 722.0 ns/op 256 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen8-24 14725010 80.52 ns/op 16 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen16-24 9553730 124.2 ns/op 32 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen21-24 7688282 152.3 ns/op 48 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen32-24 5810041 204.1 ns/op 64 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen64-24 3273080 367.0 ns/op 128 B/op 1 allocs/op -BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen128-24 1766614 688.4 ns/op 256 B/op 1 allocs/op +cpu: Apple M4 Max +BenchmarkNanoIDAllocations-16 14318704 81.72 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDAllocationsConcurrent-16 67763110 16.15 ns/op 24 B/op 1 allocs/op +BenchmarkGenerator_Read_DefaultLength-16 15188494 78.37 ns/op 24 B/op 1 allocs/op +BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_2-16 35454968 34.53 ns/op 8 B/op 1 allocs/op +BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_3-16 32779533 37.05 ns/op 8 B/op 1 allocs/op +BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_5-16 29836489 40.66 ns/op 8 B/op 1 allocs/op +BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_13-16 20298000 57.49 ns/op 16 B/op 1 allocs/op +BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_21-16 16523661 72.90 ns/op 24 B/op 1 allocs/op +BenchmarkGenerator_Read_VaryingBufferSizes/BufferSize_34-16 11567829 102.5 ns/op 48 B/op 1 allocs/op +BenchmarkGenerator_Read_ZeroLengthBuffer-16 899398803 1.334 ns/op 0 B/op 0 allocs/op +BenchmarkGenerator_Read_Concurrent/Concurrency_1-16 15924032 73.68 ns/op 24 B/op 1 allocs/op +BenchmarkGenerator_Read_Concurrent/Concurrency_2-16 30869953 39.47 ns/op 24 B/op 1 allocs/op +BenchmarkGenerator_Read_Concurrent/Concurrency_4-16 53020219 25.02 ns/op 24 B/op 1 allocs/op +BenchmarkGenerator_Read_Concurrent/Concurrency_8-16 71823493 16.26 ns/op 24 B/op 1 allocs/op +BenchmarkGenerator_Read_Concurrent/Concurrency_16-16 74829878 14.44 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen8-16 26380341 45.18 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen16-16 19585760 62.57 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen21-16 ^[16327316 71.70 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen32-16 12858915 92.76 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen64-16 7864554 152.7 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen2/IDLen128-16 4521963 263.0 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen8-16 26724024 44.68 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen16-16 19288508 61.47 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen21-16 16651855 71.67 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen32-16 13239339 91.09 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen64-16 7927832 151.5 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen16/IDLen128-16 4585581 260.9 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen8-16 27092953 44.56 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen16-16 19397608 61.66 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen21-16 16790154 71.77 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen32-16 12921525 92.47 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen64-16 7786845 152.0 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen32/IDLen128-16 4586020 261.5 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen8-16 26981778 44.63 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen16-16 19697626 61.33 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen21-16 16638607 72.65 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen32-16 12382740 94.72 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen64-16 7822154 152.6 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGeneration/ASCII_AlphabetLen64/IDLen128-16 4571776 272.1 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen8-16 19501108 62.13 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen16-16 12258480 96.82 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen21-16 10284886 114.7 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen32-16 7772995 154.8 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen64-16 4410819 272.0 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen2/IDLen128-16 2386099 501.8 ns/op 256 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen8-16 19307736 63.37 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen16-16 12347330 96.57 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen21-16 10350645 118.9 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen32-16 7597382 156.7 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen64-16 4367085 273.9 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen16/IDLen128-16 2380953 506.9 ns/op 256 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen8-16 19134736 62.90 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen16-16 12492582 96.04 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen21-16 10391311 115.0 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen32-16 7725854 156.2 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen64-16 4314513 273.6 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen32/IDLen128-16 2381019 502.9 ns/op 256 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen8-16 19200831 63.52 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen16-16 12389340 96.67 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen21-16 10312555 116.3 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen32-16 7659938 155.7 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen64-16 4388805 273.1 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGeneration/Unicode_AlphabetLen64/IDLen128-16 2385751 503.7 ns/op 256 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen8-16 137644742 7.789 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen16-16 100000000 10.73 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen21-16 93969322 13.68 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen32-16 62877154 17.81 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen64-16 40507353 30.00 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen2/IDLen128-16 23519860 52.73 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen8-16 148337209 8.224 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen16-16 100000000 10.73 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen21-16 80615584 13.32 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen32-16 67688575 17.66 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen64-16 40898517 28.74 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen16/IDLen128-16 24600330 50.13 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen8-16 148020730 8.096 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen16-16 100000000 10.78 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen21-16 91318411 14.07 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen32-16 71116905 16.99 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen64-16 40690780 28.13 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen32/IDLen128-16 24042754 49.82 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen8-16 155735688 7.741 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen16-16 100000000 11.15 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen21-16 88183687 13.26 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen32-16 67886580 16.79 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen64-16 42262760 28.11 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/ASCII_AlphabetLen64/IDLen128-16 24148390 48.57 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen8-16 95122332 12.57 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen16-16 59121673 22.50 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen21-16 43497828 27.08 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen32-16 32718980 36.79 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen64-16 17846673 66.96 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen2/IDLen128-16 9805506 121.8 ns/op 256 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen8-16 94081983 13.57 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen16-16 57457389 22.33 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen21-16 39253527 31.03 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen32-16 30329932 39.87 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen64-16 17305892 71.16 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen16/IDLen128-16 9408576 127.4 ns/op 256 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen8-16 90432381 13.56 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen16-16 44038987 23.46 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen21-16 40879766 30.02 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen32-16 30454308 41.64 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen64-16 15016314 74.21 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen32/IDLen128-16 9485343 130.4 ns/op 256 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen8-16 88650294 13.24 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen16-16 53983129 21.90 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen21-16 39779500 28.94 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen32-16 29728940 38.54 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen64-16 16351167 68.58 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDGenerationParallel/Unicode_AlphabetLen64/IDLen128-16 9917641 122.0 ns/op 256 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen8-16 23241456 45.42 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen16-16 18732742 65.11 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen21-16 15977692 72.47 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen32-16 12448131 99.06 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen64-16 7415142 164.3 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen2/IDLen128-16 4145812 289.2 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen8-16 25051995 45.72 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen16-16 19202598 62.73 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen21-16 16435147 73.21 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen32-16 12831844 94.21 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen64-16 7704615 157.2 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen16/IDLen128-16 4425217 276.7 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen8-16 25598953 45.57 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen16-16 19057614 62.66 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen21-16 16212391 73.10 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen32-16 12844366 92.96 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen64-16 7733532 159.5 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen32/IDLen128-16 4260783 281.7 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen8-16 24486859 47.67 ns/op 8 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen16-16 18676666 63.38 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen21-16 16334020 73.24 ns/op 24 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen32-16 12672018 94.54 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen64-16 7721707 155.3 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/ASCII_AlphabetLen64/IDLen128-16 4483032 267.4 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen8-16 19529527 62.71 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen16-16 12396213 97.23 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen21-16 10278896 116.3 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen32-16 7664722 156.0 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen64-16 4357148 275.2 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen2/IDLen128-16 2366166 507.0 ns/op 256 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen8-16 18755970 63.63 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen16-16 12390586 97.43 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen21-16 10318215 116.0 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen32-16 7675764 156.4 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen64-16 4367828 274.9 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen16/IDLen128-16 2368156 506.0 ns/op 256 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen8-16 19273186 62.95 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen16-16 12282088 97.11 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen21-16 10248876 116.5 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen32-16 7676949 156.4 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen64-16 4373037 273.8 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen32/IDLen128-16 2372378 505.9 ns/op 256 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen8-16 19010188 63.21 ns/op 16 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen16-16 12517303 96.70 ns/op 32 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen21-16 10282838 116.2 ns/op 48 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen32-16 7661167 156.4 ns/op 64 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen64-16 4359604 274.6 ns/op 128 B/op 1 allocs/op +BenchmarkNanoIDWithVaryingAlphabetLengths/Unicode_AlphabetLen64/IDLen128-16 2369816 506.8 ns/op 256 B/op 1 allocs/op PASS -ok github.com/sixafter/nanoid 218.742s +ok github.com/sixafter/nanoid 211.634s ``` diff --git a/nanoid.go b/nanoid.go index 4af0e65..199bb63 100644 --- a/nanoid.go +++ b/nanoid.go @@ -206,9 +206,9 @@ type runtimeConfig struct { } type generator struct { - config *runtimeConfig - randomBytesPool *sync.Pool - idPool *sync.Pool + config *runtimeConfig + entropyPool *sync.Pool + idPool *sync.Pool } // New generates a new Nano ID using the default length specified by `DefaultLength`. @@ -487,7 +487,7 @@ func NewGenerator(options ...Option) (Generator, error) { // Initialize a pool of byte slices for random data generation. // The pool helps in reusing memory buffers, reducing garbage collection overhead. - randomBytesPool := &sync.Pool{ + entropyPool := &sync.Pool{ New: func() interface{} { buf := make([]byte, config.bufferSize*config.bufferMultiplier) return &buf @@ -515,9 +515,9 @@ func NewGenerator(options ...Option) (Generator, error) { // The generator holds references to the runtime configuration and buffer pools, // facilitating efficient and thread-safe ID generation. return &generator{ - config: config, - randomBytesPool: randomBytesPool, - idPool: idPool, + config: config, + entropyPool: entropyPool, + idPool: idPool, }, nil } @@ -711,7 +711,7 @@ func (g *generator) New(length int) (string, error) { // newASCII generates a new Nano ID using the ASCII alphabet. func (g *generator) newASCII(length int) (string, error) { - randomBytesPtr := g.randomBytesPool.Get().(*[]byte) + randomBytesPtr := g.entropyPool.Get().(*[]byte) randomBytes := *randomBytesPtr bufferLen := len(randomBytes) @@ -727,7 +727,7 @@ func (g *generator) newASCII(length int) (string, error) { // Defer returning the randomBytes buffer to the pool defer func() { - g.randomBytesPool.Put(randomBytesPtr) + g.entropyPool.Put(randomBytesPtr) }() for attempts := 0; cursor < length && attempts < maxAttempts; attempts++ { @@ -764,7 +764,7 @@ func (g *generator) newASCII(length int) (string, error) { // newUnicode generates a new Nano ID using the Unicode alphabet. func (g *generator) newUnicode(length int) (string, error) { // Retrieve random bytes from the pool - randomBytesPtr := g.randomBytesPool.Get().(*[]byte) + randomBytesPtr := g.entropyPool.Get().(*[]byte) randomBytes := *randomBytesPtr bufferLen := len(randomBytes) @@ -781,7 +781,7 @@ func (g *generator) newUnicode(length int) (string, error) { // Defer returning the randomBytes buffer to the pool defer func() { - g.randomBytesPool.Put(randomBytesPtr) + g.entropyPool.Put(randomBytesPtr) }() for attempts := 0; cursor < length && attempts < maxAttempts; attempts++ { diff --git a/x/crypto/prng/prng.go b/x/crypto/prng/prng.go index 95df919..4d2cf17 100644 --- a/x/crypto/prng/prng.go +++ b/x/crypto/prng/prng.go @@ -5,9 +5,9 @@ // Package prng provides a cryptographically secure pseudo-random number generator (PRNG) // that implements the io.Reader interface. It is designed for high-performance, concurrent -// use in generating random bytes for Nano IDs. +// use in generating random bytes. // -// This package is part of the experimental "x" modules for nanoid and may be subject to change. +// This package is part of the experimental "x" modules and may be subject to change. package prng @@ -22,12 +22,36 @@ import ( // Reader is a global io.Reader that manages a pool of prng instances internally. // It allows concurrent reads without exposing pool management to the user. +// +// Example usage: +// +// buffer := make([]byte, 64) +// n, err := Reader.Read(buffer) +// if err != nil { +// // Handle error +// } +// fmt.Printf("Read %d bytes of random data: %x\n", n, buffer) var Reader io.Reader = &poolReader{} // poolReader is a custom io.Reader that uses a sync.Pool to manage prng instances. type poolReader struct{} // NewReader returns a new instance that implements the io.Reader interface. +// This instance can be used for cryptographically secure, pseudo-random byte generation. +// +// Example usage: +// +// reader, err := NewReader() +// if err != nil { +// // Handle error +// } +// +// buffer := make([]byte, 64) +// n, err := reader.Read(buffer) +// if err != nil { +// // Handle error +// } +// fmt.Printf("Read %d bytes of random data: %x\n", n, buffer) func NewReader() (io.Reader, error) { return &poolReader{}, nil } @@ -35,13 +59,27 @@ func NewReader() (io.Reader, error) { // Read fills the provided byte slice 'b' with random data generated by a prng instance from the pool. // It acquires a prng from the pool, performs the read, and returns the prng to the pool. // If the prng instance is an errorPRNG, it returns the associated error. +// +// This method allows for efficient reuse of PRNG instances, reducing contention on crypto/rand.Reader. +// +// Example usage: +// +// buffer := make([]byte, 32) +// n, err := Reader.Read(buffer) +// if err != nil { +// // Handle error +// } +// fmt.Printf("Read %d bytes of random data: %x\n", n, buffer) func (r *poolReader) Read(b []byte) (int, error) { - prngInstance := prngPool.Get().(io.Reader) - defer prngPool.Put(prngInstance) - return prngInstance.Read(b) + p := prngPool.Get().(io.Reader) + defer prngPool.Put(p) + return p.Read(b) } // prng represents a cryptographically secure pseudo-random number generator that implements io.Reader. +// It utilizes the ChaCha20 cipher stream to generate random bytes. +// +// Each prng instance is initialized with a unique key and nonce sourced from crypto/rand.Reader. type prng struct { stream *chacha20.Cipher zero []byte @@ -49,18 +87,24 @@ type prng struct { // errorPRNG is a special prng that always returns an error on Read. // It is used to signify a failure in prng initialization. +// +// This struct implements the io.Reader interface, but its Read method always fails. type errorPRNG struct { err error } // Read implements the io.Reader interface for errorPRNG. // It always returns an error, indicating prng initialization failure. -func (e *errorPRNG) Read(b []byte) (int, error) { +// +// This method ensures that any read operation using an errorPRNG instance fails gracefully. +func (e *errorPRNG) Read(_ []byte) (int, error) { return 0, e.err } // newPRNG initializes and returns a new prng instance. // It reads a unique key and nonce from crypto/rand.Reader to seed the ChaCha20 cipher. +// +// Returns an error if key or nonce generation fails, or if the cipher cannot be created. func newPRNG() (*prng, error) { // ChaCha20 key is 32 bytes (256 bits) key := make([]byte, chacha20.KeySize) @@ -89,7 +133,10 @@ func newPRNG() (*prng, error) { // Read fills the provided byte slice 'b' with random data generated by the prng. // It implements the io.Reader interface. +// // This method is safe for exclusive use by a single goroutine. +// +// It generates random bytes by encrypting zero bytes using the ChaCha20 cipher stream. func (p *prng) Read(b []byte) (int, error) { // Reuse the zero buffer if it's large enough if cap(p.zero) < len(b) { @@ -106,13 +153,15 @@ func (p *prng) Read(b []byte) (int, error) { // prngPool is a sync.Pool that holds prng instances to reduce contention on crypto/rand.Reader. // It allows multiple goroutines to acquire separate prng instances for concurrent random byte generation. +// +// Each prng instance is either a valid prng or an errorPRNG if initialization failed. var prngPool = sync.Pool{ New: func() interface{} { - prngInstance, err := newPRNG() + p, err := newPRNG() if err != nil { // Instead of panicking, return an errorPRNG instance with the error. return &errorPRNG{err: fmt.Errorf("prngPool.New: failed to create prng: %v", err)} } - return prngInstance + return p }, } diff --git a/x/crypto/prng/prng_test.go b/x/crypto/prng/prng_test.go index a13b77f..d4d2424 100644 --- a/x/crypto/prng/prng_test.go +++ b/x/crypto/prng/prng_test.go @@ -366,20 +366,3 @@ func TestPRNG_ReadConsistency(t *testing.T) { } } } - -// TestPRNG_ReadErrorScenario simulates a read error by configuring the Reader to use a pool -// that always returns an errorPRNG instance. This ensures that the application correctly -// handles read failures. -func TestPRNG_ReadErrorScenario(t *testing.T) { - t.Parallel() // Enable parallel execution of this test - - // Since newPoolReader has been removed, we cannot inject a custom pool. - // Instead, we can temporarily modify the Reader's behavior if possible. - // If Reader is a global variable, this approach might not be safe. - // Alternatively, consider refactoring the Reader to allow dependency injection for better testability. - - // Placeholder for error scenario testing. - // Implementing this requires modifications to the prng package to support injecting - // a mock or error-producing Reader. Without such modifications, it's not feasible. - t.Skip("ReadErrorScenario test is skipped because dependency injection is not supported.") -}