benchmark.js
This file
Path
test/benchmark.js
87 lines · 1.9 KiB · JavaScript
Last changed by
Remove unnecessary import for modern Node.jsAndrey Sitnikbefore adoption87f2821
History of this fileTake it
The walk stopped after 200 commits: lines older than cdc3edc point at it.
Update size limitAndrey Sitnikbefore adoptioncdc3edc
lines 1–5why, one step back1#!/usr/bin/env node23import { v4 as lukeed4 } from '@lukeed/uuid'4import { v4 as napiV4 } from '@napi-rs/uuid'5import { styleText } from 'node:util'Add nope-id to benchmark (#591)Andrey Sitnikbefore adoptione7d205b
line 6why, one step back6import { nopeid } from 'nope-id'Update size limitAndrey Sitnikbefore adoptioncdc3edc
lines 7–15why, one step back7import rndm from 'rndm'8import srs from 'secure-random-string'9import { Bench } from 'tinybench'10import { uid } from 'uid'11import uidSafe from 'uid-safe'12import { uid as uidSecure } from 'uid/secure'13import { v4 as uuid4 } from 'uuid'1415import { nanoid as browser } from '../index.browser.js'Port amazing nope-id optimizations (#602)Andrey Sitnikbefore adoptionb1bb75f
line 16why, one step back16import { nanoid, customAlphabet } from '../index.js'Update size limitAndrey Sitnikbefore adoptioncdc3edc
lines 17–20why, one step back17import { nanoid as nonSecure } from '../non-secure/index.js'1819let bench = new Bench()20Port amazing nope-id optimizations (#602)Andrey Sitnikbefore adoptionb1bb75f
line 21why, one step back21let nanoid2 = customAlphabet('1234567890abcdef-', 21)Update size limitAndrey Sitnikbefore adoptioncdc3edc
lines 22–23why, one step back2223benchUpdate nope-id for benchmark (#593)Andrey Sitnikbefore adoption78f4a02
lines 24–26why, one step back24 .add('nope-id', () => {25 nopeid()26 })Port amazing nope-id optimizations (#602)Andrey Sitnikbefore adoptionb1bb75f
lines 27–32why, one step back27 .add('nanoid', () => {28 nanoid()29 })30 .add('customAlphabet', () => {31 nanoid2()32 })Fix benchmark regressionAndrey Sitnikbefore adoption9abd691
lines 33–65why, one step back33 .add('crypto.randomUUID', () => {34 crypto.randomUUID()35 })36 .add('uuid v4', () => {37 uuid4()38 })39 .add('@napi-rs/uuid', () => {40 napiV4()41 })42 .add('uid/secure', () => {43 uidSecure(32)44 })45 .add('@lukeed/uuid', () => {46 lukeed4()47 })48 .add('nanoid for browser', () => {49 browser()50 })51 .add('secure-random-string', () => {52 srs()53 })54 .add('uid-safe.sync', () => {55 uidSafe.sync(14)56 })57 .add('uid', () => {58 uid(32)59 })60 .add('nanoid/non-secure', () => {61 nonSecure()62 })63 .add('rndm', () => {64 rndm(21)65 })Update size limitAndrey Sitnikbefore adoptioncdc3edc
lines 66–71why, one step back6667let longestTask = bench.tasks.reduce((maxLength, task) => {68 return Math.max(maxLength, task.name.length)69}, 0)7071bench.addEventListener('cycle', ({ task }) => {Fix benchmark for tinybench v6 (#565)Mahmoud Hamdybefore adoption0d9f226
lines 72–74why, one step back72 let hz = (+task.result.throughput.mean.toFixed(0))73 .toLocaleString('en-US')74 .padStart(14)Update size limitAndrey Sitnikbefore adoptioncdc3edc
lines 75–87why, one step back7576 let name = task.name.padEnd(longestTask)77 let value = styleText('bold', hz)78 let units = styleText('dim', 'ops/sec')7980 if (task.name === 'uid') {81 process.stdout.write('\nNon-secure:\n')82 }8384 process.stdout.write(`${name}${value} ${units}\n`)85})8687await bench.run({ warmup: true })