Speed up random generator
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Andrey Sitnik · committed by Andrey Sitnik · parent a52d511 · Browse files · 3 files·+27 added−21 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+27 added−21 removed
- other:+27 added−21 removed
Provenance
- Commit
fd51e72- Tree
a54f8dc- Author
Andrey Sitnik <andrey@sitnik.ru>- Committer
Andrey Sitnik <andrey@sitnik.ru>- Parent
a52d511
3 files changed+27 added−21 removed
modified:random.js+7 added-1 removed
1234567891051112131415var crypto = require('crypto')
if (crypto.randomFillSync) { var buffers = { } module.exports = function (bytes) { var buffer = buffers[bytes] if (!buffer) { buffer = Buffer.allocUnsafe(bytes) if (bytes <= 255) buffers[bytes] = buffer } return crypto.randomFillSync(Buffer.allocUnsafe(bytes)) return crypto.randomFillSync(buffer) }} else { module.exports = crypto.randomBytes}modified:README-cn.md+10 added-10 removed
65 unmodified lines66 ## 性能基准(Benchmark)67 68 ```rust69 $ ./test/benchmark70-nanoid 400,771 ops/sec71-nanoid/generate 401,995 ops/sec72-uid.sync 357,449 ops/sec73-uuid/v4 353,771 ops/sec74-shortid 33,758 ops/sec70+nanoid 413,579 ops/sec71+nanoid/generate 401,349 ops/sec72+uid.sync 354,882 ops/sec73+uuid/v4 353,836 ops/sec74+shortid 39,152 ops/sec75 76 Async:77-nanoid/async 85,251 ops/sec78-nanoid/async/generate 78,809 ops/sec79-uid 76,991 ops/sec77+nanoid/async 85,168 ops/sec78+nanoid/async/generate 81,037 ops/sec79+uid 78,426 ops/sec80 81 Non-secure:82-nanoid/non-secure 2,807,009 ops/sec83-rndm 2,629,172 ops/sec82+nanoid/non-secure 2,718,186 ops/sec83+rndm 2,544,612 ops/sec84 ```85 86 87 ## 使用方法129 unmodified linesmodified:README.md+10 added-10 removed
78 unmodified lines79 ## Benchmark80 81 ```rust82 $ ./test/benchmark83-nanoid 400,771 ops/sec84-nanoid/generate 401,995 ops/sec85-uid.sync 357,449 ops/sec86-uuid/v4 353,771 ops/sec87-shortid 33,758 ops/sec83+nanoid 413,579 ops/sec84+nanoid/generate 401,349 ops/sec85+uid.sync 354,882 ops/sec86+uuid/v4 353,836 ops/sec87+shortid 39,152 ops/sec88 89 Async:90-nanoid/async 85,251 ops/sec91-nanoid/async/generate 78,809 ops/sec92-uid 76,991 ops/sec90+nanoid/async 85,168 ops/sec91+nanoid/async/generate 81,037 ops/sec92+uid 78,426 ops/sec93 94 Non-secure:95-nanoid/non-secure 2,807,009 ops/sec96-rndm 2,629,172 ops/sec95+nanoid/non-secure 2,718,186 ops/sec96+rndm 2,544,612 ops/sec97 ```98 99 100 ## Usage171 unmodified lines