diff --git a/packages/argon2/benchmark/argon2.ts b/packages/argon2/benchmark/argon2.ts index 4d819e5a..711e0126 100644 --- a/packages/argon2/benchmark/argon2.ts +++ b/packages/argon2/benchmark/argon2.ts @@ -32,7 +32,6 @@ bench console.assert(await nodeArgon2.verify(HASHED, PASSWORD)) }) -await bench.warmup() await bench.run() console.table(bench.table()) diff --git a/packages/argon2/package.json b/packages/argon2/package.json index d87ad849..fc82b5c6 100644 --- a/packages/argon2/package.json +++ b/packages/argon2/package.json @@ -65,6 +65,6 @@ "@napi-rs/cli": "^3.0.0-alpha.64", "argon2": "^0.41.0", "cross-env": "^7.0.3", - "tinybench": "^2.9.0" + "tinybench": "^3.0.0" } } diff --git a/packages/bcrypt/benchmark/bcrypt.ts b/packages/bcrypt/benchmark/bcrypt.ts index b9958517..96e1ccf7 100644 --- a/packages/bcrypt/benchmark/bcrypt.ts +++ b/packages/bcrypt/benchmark/bcrypt.ts @@ -3,13 +3,15 @@ import openwall from '@cwasm/openwall-bcrypt' import { hashSync, compare, genSaltSync } from 'bcrypt' import bcryptjs from 'bcryptjs' import { Bench } from 'tinybench' -import chalk from 'chalk' import { hashSync as napiHashSync, verifySync, genSaltSync as napiGenSaltSync } from '../binding.js' const password = 'node-rust-password' -const syncHashSuite = new Bench() +const syncHashSuite = new Bench({ + name: 'Hash benchmark', +}) + syncHashSuite .add('@node-rs/bcrypt', () => { napiHashSync(password, 10) @@ -27,13 +29,13 @@ syncHashSuite openwall.hashSync(password, 10) }) -await syncHashSuite.warmup() await syncHashSuite.run() -console.info(chalk.green('Hash benchmark')) console.table(syncHashSuite.table()) -const verifySuite = new Bench() +const verifySuite = new Bench({ + name: 'Verify benchmark`', +}) const hashed = napiHashSync(password, 12) verifySuite .add('@node-rs/bcrypt', () => { @@ -46,13 +48,13 @@ verifySuite bcryptjs.compareSync(password, hashed) }) -await verifySuite.warmup() await verifySuite.run() -console.info(chalk.green('Verify benchmark')) console.table(verifySuite.table()) -const genSaltSuite = new Bench() +const genSaltSuite = new Bench({ + name: 'GenSalt benchmark', +}) genSaltSuite .add('@node-rs/bcrypt', () => { napiGenSaltSync(12) @@ -70,8 +72,6 @@ genSaltSuite openwall.genSaltSync(12) }) -await genSaltSuite.warmup() await genSaltSuite.run() -console.info(chalk.green('GenSalt benchmark')) console.table(genSaltSuite.table()) diff --git a/packages/bcrypt/package.json b/packages/bcrypt/package.json index 0d585579..22bcf79e 100644 --- a/packages/bcrypt/package.json +++ b/packages/bcrypt/package.json @@ -78,7 +78,7 @@ "bcrypt": "^5.1.1", "bcryptjs": "^2.4.3", "cross-env": "^7.0.3", - "tinybench": "^2.9.0" + "tinybench": "^3.0.0" }, "funding": { "type": "github", diff --git a/packages/crc32/benchmark/crc32.ts b/packages/crc32/benchmark/crc32.ts index a9daeae6..b8a462ce 100644 --- a/packages/crc32/benchmark/crc32.ts +++ b/packages/crc32/benchmark/crc32.ts @@ -1,5 +1,4 @@ import { Bench } from 'tinybench' -import chalk from 'chalk' import { crc32 as crc32Node } from 'crc' import Sse4Crc32 from 'sse4_crc32' @@ -26,66 +25,66 @@ const initialCrc32c = Sse4Crc32.calculate(TEST_BUFFER) console.assert(crc32(TEST_BUFFER) === initialCrc32) console.assert(crc32c(TEST_BUFFER) === initialCrc32c) -const suite = new Bench() +const suite = new Bench({ + name: 'crc32c without initial crc', +}) -await suite +suite .add('@node/rs crc32c', () => { crc32c(TEST_BUFFER) }) .add('sse4_crc32', () => { Sse4Crc32.calculate(TEST_BUFFER) }) - .warmup() await suite.run() -console.info(chalk.green('crc32c without initial crc')) console.table(suite.table()) -const suite2 = new Bench() +const suite2 = new Bench({ + name: 'crc32c with initial crc', +}) -await suite2 +suite2 .add('@node/rs crc32c', () => { crc32c(TEST_BUFFER, initialCrc32c) }) .add('sse4_crc32', () => { Sse4Crc32.calculate(TEST_BUFFER, initialCrc32c) }) - .warmup() await suite2.run() -console.info(chalk.green('crc32c with initial crc')) console.table(suite2.table()) -const suite3 = new Bench() +const suite3 = new Bench({ + name: 'crc32 without initial crc', +}) -await suite3 +suite3 .add('@node/rs crc32', () => { crc32(TEST_BUFFER) }) .add('Node crc', () => { crc32Node(TEST_BUFFER) }) - .warmup() await suite3.run() -console.info(chalk.green('crc32 without initial crc')) console.table(suite3.table()) -const suite4 = new Bench() +const suite4 = new Bench({ + name: 'crc32 with initial crc', +}) -await suite4 +suite4 .add('@node/rs crc32', () => { crc32(TEST_BUFFER, initialCrc32) }) .add('Node crc32', () => { crc32Node(TEST_BUFFER, initialCrc32) }) - .warmup() await suite4.run() -console.info(chalk.green('crc32 with initial crc')) console.table(suite4.table()) diff --git a/packages/crc32/package.json b/packages/crc32/package.json index dc266e95..8fc9bfd1 100644 --- a/packages/crc32/package.json +++ b/packages/crc32/package.json @@ -71,7 +71,7 @@ "crc": "^4.3.2", "cross-env": "^7.0.3", "sse4_crc32": "^7.0.0", - "tinybench": "^2.9.0" + "tinybench": "^3.0.0" }, "funding": { "type": "github", diff --git a/packages/jieba/benchmark/jieba.ts b/packages/jieba/benchmark/jieba.ts index 7ca31d0e..9e52b3fa 100644 --- a/packages/jieba/benchmark/jieba.ts +++ b/packages/jieba/benchmark/jieba.ts @@ -3,7 +3,6 @@ import { join } from 'node:path' import { fileURLToPath } from 'node:url' import { Bench } from 'tinybench' -import chalk from 'chalk' import nodejieba from 'nodejieba' import { Jieba } from '../index.js' @@ -32,16 +31,15 @@ async function createBench( napi: () => any[], jieba: () => any[], ) { - const suite = new Bench() + const suite = new Bench({ + name: suitename, + }) console.assert(transform(napi()) === transform(jieba())) suite.add('@node-rs/jieba', napi).add('nodejieba', jieba) - await suite.warmup() - await suite.run() - console.info(chalk.green(`Benchmark ${suitename} result`)) console.table(suite.table()) } diff --git a/packages/jieba/package.json b/packages/jieba/package.json index 38af0341..ac043cdd 100644 --- a/packages/jieba/package.json +++ b/packages/jieba/package.json @@ -71,7 +71,7 @@ "@napi-rs/cli": "^3.0.0-alpha.64", "cross-env": "^7.0.3", "nodejieba": "^3.0.0", - "tinybench": "^2.9.0" + "tinybench": "^3.0.0" }, "funding": { "type": "github", diff --git a/packages/jsonwebtoken/benchmark/jsonwebtoken.ts b/packages/jsonwebtoken/benchmark/jsonwebtoken.ts index 0a3147b1..6e8760cb 100644 --- a/packages/jsonwebtoken/benchmark/jsonwebtoken.ts +++ b/packages/jsonwebtoken/benchmark/jsonwebtoken.ts @@ -1,5 +1,4 @@ import { Bench } from 'tinybench' -import chalk from 'chalk' import nodeJsonwebtoken, { type PrivateKey, type Secret, type PublicKey, type GetPublicKeyOrSecret } from 'jsonwebtoken' import { sign, verify, verifySync, signSync } from '../index.js' @@ -43,9 +42,11 @@ const jwtClaims = { } const token = nodeJwtSignSync(jwtClaims, secretKey) -const suite = new Bench() +const suite = new Bench({ + name: 'Sign token', +}) -await suite +suite .add('@node-rs/jsonwebtoken', async () => { await sign(jwtClaims, secretKey) }) @@ -58,15 +59,15 @@ await suite .add('jsonwebtoken sync', () => { nodeJwtSignSync(jwtClaims, secretKey) }) - .warmup() await suite.run() -console.info(chalk.green('Sign token')) console.table(suite.table()) -const verifySuite = new Bench() +const verifySuite = new Bench({ + name: 'Verify token', +}) -await verifySuite +verifySuite .add('@node-rs/jsonwebtoken', async () => { await verify(token, secretKey) }) @@ -79,8 +80,6 @@ await verifySuite .add('jsonwebtoken sync', () => { nodeJwtVerifySync(token, secretKey) }) - .warmup() await verifySuite.run() -console.info(chalk.green('Verify token')) console.table(verifySuite.table()) diff --git a/packages/jsonwebtoken/package.json b/packages/jsonwebtoken/package.json index 2af25c66..5b43de9c 100644 --- a/packages/jsonwebtoken/package.json +++ b/packages/jsonwebtoken/package.json @@ -69,6 +69,6 @@ "@types/jsonwebtoken": "^9.0.6", "cross-env": "^7.0.3", "jsonwebtoken": "^9.0.2", - "tinybench": "^2.9.0" + "tinybench": "^3.0.0" } } diff --git a/packages/xxhash/benchmark/xxhash.ts b/packages/xxhash/benchmark/xxhash.ts index 5133353f..c1db17ee 100644 --- a/packages/xxhash/benchmark/xxhash.ts +++ b/packages/xxhash/benchmark/xxhash.ts @@ -3,7 +3,6 @@ import { join } from 'node:path' import { fileURLToPath } from 'node:url' import { Bench } from 'tinybench' -import chalk from 'chalk' // @ts-expect-error import createWasmHasher from 'webpack/lib/util/hash/xxhash64.js' // @ts-expect-error @@ -16,9 +15,11 @@ const FX = readFileSync(join(fileURLToPath(import.meta.url), '..', '..', '..', ' const wasmHasher = createWasmHasher() -const suite = new Bench() +const suite = new Bench({ + name: 'xxh32 without initial seed', +}) -await suite +suite .add('@node-rs/xxhash h32', () => { xxh32(FX, 0) }) @@ -28,32 +29,31 @@ await suite .add('xxhashjs h32', () => { xxhashjs.h32(FX, 0).toNumber() }) - .warmup() - -console.info(chalk.green('xxh32 without initial seed')) await suite.run() console.table(suite.table()) -const multiStepSuite = new Bench() +const multiStepSuite = new Bench({ + name: 'xxh32 without initial seed multi step', +}) -await multiStepSuite +multiStepSuite .add('@node-rs/xxhash h32', () => { new Xxh32().update(FX).digest() }) .add('xxhashjs h32', () => { xxhashjs.h32().update(FX).digest().toNumber() }) - .warmup() await multiStepSuite.run() -console.info(chalk.green('xxh32 without initial seed multi step')) console.table(multiStepSuite.table()) -const xx64Suite = new Bench() +const xx64Suite = new Bench({ + name: 'xxh64 without initial seed', +}) -await xx64Suite +xx64Suite .add('@node-rs/xxhash 64', () => { xxh64(FX).toString(16) }) @@ -67,16 +67,16 @@ await xx64Suite .add('xxhashjs h64', () => { xxhashjs.h64(FX, 0).toString(16) }) - .warmup() await xx64Suite.run() -console.info(chalk.green('xxh64 without initial seed')) console.table(xx64Suite.table()) -const multiStepSuite64 = new Bench() +const multiStepSuite64 = new Bench({ + name: 'xxh64 without initial seed multi step', +}) -await multiStepSuite64 +multiStepSuite64 .add('@node-rs/xxhash 64', () => { new Xxh64().update(FX).digest().toString(16) }) @@ -87,9 +87,7 @@ await multiStepSuite64 .add('xxhashjs h64', () => { xxhashjs.h64(0).update(FX).digest().toString(16) }) - .warmup() await multiStepSuite64.run() -console.info(chalk.green('xxh64 without initial seed multi step')) console.table(multiStepSuite64.table()) diff --git a/packages/xxhash/package.json b/packages/xxhash/package.json index d460980c..a0c928b2 100644 --- a/packages/xxhash/package.json +++ b/packages/xxhash/package.json @@ -70,7 +70,7 @@ "@oxc-node/core": "^0.0.15", "@types/xxhashjs": "^0.2.4", "cross-env": "^7.0.3", - "tinybench": "^2.9.0", + "tinybench": "^3.0.0", "webpack": "^5.92.1", "xxhash": "^0.3.0", "xxhashjs": "^0.2.2" diff --git a/yarn.lock b/yarn.lock index 9858a58b..c2eb8743 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1041,7 +1041,7 @@ __metadata: "@napi-rs/cli": "npm:^3.0.0-alpha.64" argon2: "npm:^0.41.0" cross-env: "npm:^7.0.3" - tinybench: "npm:^2.9.0" + tinybench: "npm:^3.0.0" languageName: unknown linkType: soft @@ -1057,7 +1057,7 @@ __metadata: bcrypt: "npm:^5.1.1" bcryptjs: "npm:^2.4.3" cross-env: "npm:^7.0.3" - tinybench: "npm:^2.9.0" + tinybench: "npm:^3.0.0" languageName: unknown linkType: soft @@ -1072,7 +1072,7 @@ __metadata: crc: "npm:^4.3.2" cross-env: "npm:^7.0.3" sse4_crc32: "npm:^7.0.0" - tinybench: "npm:^2.9.0" + tinybench: "npm:^3.0.0" languageName: unknown linkType: soft @@ -1091,7 +1091,7 @@ __metadata: "@napi-rs/cli": "npm:^3.0.0-alpha.64" cross-env: "npm:^7.0.3" nodejieba: "npm:^3.0.0" - tinybench: "npm:^2.9.0" + tinybench: "npm:^3.0.0" languageName: unknown linkType: soft @@ -1104,7 +1104,7 @@ __metadata: "@types/jsonwebtoken": "npm:^9.0.6" cross-env: "npm:^7.0.3" jsonwebtoken: "npm:^9.0.2" - tinybench: "npm:^2.9.0" + tinybench: "npm:^3.0.0" languageName: unknown linkType: soft @@ -1116,7 +1116,7 @@ __metadata: "@oxc-node/core": "npm:^0.0.15" "@types/xxhashjs": "npm:^0.2.4" cross-env: "npm:^7.0.3" - tinybench: "npm:^2.9.0" + tinybench: "npm:^3.0.0" webpack: "npm:^5.92.1" xxhash: "npm:^0.3.0" xxhashjs: "npm:^0.2.2" @@ -8283,10 +8283,10 @@ __metadata: languageName: node linkType: hard -"tinybench@npm:^2.9.0": - version: 2.9.0 - resolution: "tinybench@npm:2.9.0" - checksum: 10c0/c3500b0f60d2eb8db65250afe750b66d51623057ee88720b7f064894a6cb7eb93360ca824a60a31ab16dab30c7b1f06efe0795b352e37914a9d4bad86386a20c +"tinybench@npm:^3.0.0": + version: 3.0.0 + resolution: "tinybench@npm:3.0.0" + checksum: 10c0/47d5f532b12be9e7898a7a9048428ba88fd8e1a2ceb3ddd46a297cfc1e90130b18866c3deacd423778d53a8de7267d0e80acdf964c5490891b78d31e06742821 languageName: node linkType: hard