change benchmark to the tinybench (#483)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Pavel Gusev · committed by GitHub · parent 2b18fea · Browse files · 3 files·+26 added−36 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+26 added−36 removed
- tests:+17 added−14 removed
- other:+9 added−22 removed
Provenance
- Commit
235d347- Tree
6c28c00- Author
Pavel Gusev <freezefess@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
2b18fea
3 files changed+26 added−36 removed
modified:test/benchmark.js+17 added-14 removed
123455678910111213141516171819202021222324252627282930303132333434 unmodified lines6970717273737475767778798081828374757677787980818283848586#!/usr/bin/env node
import { v4 as lukeed4 } from '@lukeed/uuid'import { v4 as napiV4 } from '@napi-rs/uuid'import benchmark from 'benchmark'import crypto from 'node:crypto'import { styleText } from 'node:util'import rndm from 'rndm'import srs from 'secure-random-string'import shortid from 'shortid'import { Bench } from 'tinybench'import { uid } from 'uid'import uidSafe from 'uid-safe'import { uid as uidSecure } from 'uid/secure'import { v4 as uuid4 } from 'uuid'
import { nanoid as browser } from '../index.browser.js'import { customAlphabet, nanoid } from '../index.js'import { nanoid as nonSecure } from '../non-secure/index.js'
let suite = new benchmark.Suite()let bench = new Bench()
let nanoid2 = customAlphabet('1234567890abcdef-', 10)
function formatNumber(number) { return String(number) .replace(/\d{3}$/, ',$&') .replace(/^(\d|\d\d)(\d{3},)/, '$1,$2')}
suitebench .add('crypto.randomUUID', () => { crypto.randomUUID() }) .add('uuid v4', () => {34 unmodified lines }) .add('rndm', () => { rndm(21) })
.on('cycle', event => { let name = event.target.name.padEnd('async secure-random-string'.length) let hz = formatNumber(event.target.hz.toFixed(0)).padStart(10) if (event.target.name === 'uid') { name = '\nNon-secure:\n' + name } process.stdout.write( `${name}${styleText('bold', hz)}${styleText('dim', ' ops/sec')}\n` ) }) .run()bench.addEventListener('cycle', event => { let name = event.task.name.padEnd('async secure-random-string'.length) let hz = formatNumber(event.task.result.hz.toFixed(0)).padStart(10) if (event.task.name === 'uid') { name = '\nNon-secure:\n' + name } process.stdout.write( `${name}${styleText('bold', hz)}${styleText('dim', ' ops/sec')}\n` )})
await bench.warmup()await bench.run()modified:package.json+1 added-1 removed
53 unmodified lines54 "@originjs/vite-plugin-commonjs": "^1.0.3",55 "@size-limit/file": "^11.1.4",56 "@size-limit/webpack": "^11.1.4",57 "@types/node": "^20.14.6",58- "benchmark": "^2.1.4",58 "better-node-test": "^0.5.1",59 "c8": "^10.1.2",60 "clean-publish": "^5.0.0",61 "eslint": "^9.5.0",1 unmodified line63 "secure-random-string": "^1.1.3",64 "shortid": "^2.2.16",65 "size-limit": "^11.1.4",66 "terser": "^5.31.1",67+ "tinybench": "^2.8.0",68 "uid": "^2.0.2",69 "uid-safe": "^2.1.5",70 "uuid": "^10.0.0",71 "vite": "^5.3.1"58 unmodified linesmodified:pnpm-lock.yaml+8 added-21 removed
30 unmodified lines31 version: 11.1.4(size-limit@11.1.4)32 '@types/node':33 specifier: ^20.14.634 version: 20.14.635- benchmark:36- specifier: ^2.1.437- version: 2.1.435 better-node-test:36 specifier: ^0.5.137 version: 0.5.138 c8:19 unmodified lines58 version: 11.1.459 terser:60 specifier: ^5.31.161 version: 5.31.162+ tinybench:63+ specifier: ^2.8.064+ version: 2.8.065 uid:66 specifier: ^2.0.267 version: 2.0.268 uid-safe:745 unmodified lines814 815 balanced-match@1.0.2:816 resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}817 818- benchmark@2.1.4:819- resolution: {integrity: sha512-l9MlfN4M1K/H2fbhfMy3B7vJd6AGKJVQn2h6Sg/Yx+KckoUA7ewS5Vv6TjSq18ooE1kS9hhAlQRH3AkXIh/aOQ==}820-818 better-node-test@0.5.1:819 resolution: {integrity: sha512-L5iVFSXrX+hCJ4OItXGzDQ+HMAPUcoXu6Zwnlha7mtkoBu3sRZb4PtkOFJg/mJnIerKfbgRl4f4qDqcDLfM5rA==}820 engines: {node: ^18.19.0 || >=20.0.0}821 hasBin: true809 unmodified lines1631 1632 lodash.merge@4.6.2:1633 resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==}1634 1638- lodash@4.17.21:1639- resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}1640-1635 lru-cache@10.2.2:1636 resolution: {integrity: sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ==}1637 engines: {node: 14 || >=16.14}1638 146 unmodified lines1785 picomatch@2.3.1:1786 resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}1787 engines: {node: '>=8.6'}1788 1795- platform@1.3.6:1796- resolution: {integrity: sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==}1797-1789 possible-typed-array-names@1.0.0:1790 resolution: {integrity: sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==}1791 engines: {node: '>= 0.4'}1792 225 unmodified lines2018 2019 text-table@0.2.0:2020 resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==}2021 2022+ tinybench@2.8.0:2023+ resolution: {integrity: sha512-1/eK7zUnIklz4JUUlL+658n58XO2hHLQfSk1Zf2LKieUjxidN16eKFEoDEfjHc3ohofSSqK3X5yO6VGb6iW8Lw==}2024+2025 to-fast-properties@2.0.0:2026 resolution: {integrity: sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==}2027 engines: {node: '>=4'}2028 902 unmodified lines2931 possible-typed-array-names: 1.0.02932 2933 balanced-match@1.0.2: {}2934 2941- benchmark@2.1.4:2942- dependencies:2943- lodash: 4.17.212944- platform: 1.3.62945-2935 better-node-test@0.5.1: {}2936 2937 binary-extensions@2.3.0: {}2938 856 unmodified lines3795 p-locate: 5.0.03796 3797 lodash.merge@4.6.2: {}3798 3810- lodash@4.17.21: {}3811-3799 lru-cache@10.2.2: {}3800 3801 lru-cache@5.1.1:3802 dependencies:125 unmodified lines3928 picocolors@1.0.1: {}3929 3930 picomatch@2.3.1: {}3931 3945- platform@1.3.6: {}3946-3932 possible-typed-array-names@1.0.0: {}3933 3934 postcss@8.4.38:3935 dependencies:239 unmodified lines4175 minimatch: 9.0.44176 4177 text-table@0.2.0: {}4178 4179+ tinybench@2.8.0: {}4180+4181 to-fast-properties@2.0.0: {}4182 4183 to-regex-range@5.0.1:4184 dependencies:198 unmodified lines