From 582961977d5a5b1e8f91863677568dd6770b12a9 Mon Sep 17 00:00:00 2001 From: FUJI Goro Date: Tue, 30 Dec 2025 10:58:01 +0900 Subject: [PATCH] fix benchmark scripts for node, bun, and deno --- benchmark/benchmark-from-msgpack-lite.ts | 2 +- benchmark/decode-string.ts | 2 +- benchmark/encode-string.ts | 2 +- benchmark/key-decoder.ts | 8 +++++--- benchmark/package.json | 1 + benchmark/profile-decode.ts | 2 +- benchmark/profile-encode.ts | 2 +- benchmark/string.ts | 2 +- benchmark/sync-vs-async.ts | 12 +++++++----- benchmark/timestamp-ext.ts | 2 +- 10 files changed, 20 insertions(+), 15 deletions(-) diff --git a/benchmark/benchmark-from-msgpack-lite.ts b/benchmark/benchmark-from-msgpack-lite.ts index c03cd0ad..40ac6f9b 100644 --- a/benchmark/benchmark-from-msgpack-lite.ts +++ b/benchmark/benchmark-from-msgpack-lite.ts @@ -1,7 +1,7 @@ /* eslint-disable */ // original: https://raw.githubusercontent.com/kawanet/msgpack-lite/master/lib/benchmark.js -var msgpack_msgpack = require("../src"); +var msgpack_msgpack = require("../src/index.ts"); var msgpack_node = try_require("msgpack"); var msgpack_lite = try_require("msgpack-lite"); diff --git a/benchmark/decode-string.ts b/benchmark/decode-string.ts index a6ea1467..3e6bfbb1 100644 --- a/benchmark/decode-string.ts +++ b/benchmark/decode-string.ts @@ -1,5 +1,5 @@ /* eslint-disable no-console */ -import { utf8EncodeJs, utf8Count, utf8DecodeJs, utf8DecodeTD } from "../src/utils/utf8"; +import { utf8EncodeJs, utf8Count, utf8DecodeJs, utf8DecodeTD } from "../src/utils/utf8.ts"; // @ts-ignore import Benchmark from "benchmark"; diff --git a/benchmark/encode-string.ts b/benchmark/encode-string.ts index 3f6aac6c..df1b2835 100644 --- a/benchmark/encode-string.ts +++ b/benchmark/encode-string.ts @@ -1,5 +1,5 @@ /* eslint-disable no-console */ -import { utf8EncodeJs, utf8Count, utf8EncodeTE } from "../src/utils/utf8"; +import { utf8EncodeJs, utf8Count, utf8EncodeTE } from "../src/utils/utf8.ts"; // @ts-ignore import Benchmark from "benchmark"; diff --git a/benchmark/key-decoder.ts b/benchmark/key-decoder.ts index 594bbab2..dec38f30 100644 --- a/benchmark/key-decoder.ts +++ b/benchmark/key-decoder.ts @@ -1,9 +1,11 @@ /* eslint-disable no-console */ -import { utf8EncodeJs, utf8Count, utf8DecodeJs } from "../src/utils/utf8"; +import { utf8EncodeJs, utf8Count, utf8DecodeJs } from "../src/utils/utf8.ts"; +import { CachedKeyDecoder } from "../src/CachedKeyDecoder.ts"; + +import data from "./benchmark-from-msgpack-lite-data.json" with { type: "json" }; // @ts-ignore import Benchmark from "benchmark"; -import { CachedKeyDecoder } from "../src/CachedKeyDecoder"; type InputType = { bytes: Uint8Array; @@ -11,7 +13,7 @@ type InputType = { str: string; }; -const keys: Array = Object.keys(require("./benchmark-from-msgpack-lite-data.json")).map((str) => { +const keys: Array = Object.keys(data).map((str) => { const byteLength = utf8Count(str); const bytes = new Uint8Array(new ArrayBuffer(byteLength)); utf8EncodeJs(str, bytes, 0); diff --git a/benchmark/package.json b/benchmark/package.json index 161581b0..ddc30b8c 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -2,6 +2,7 @@ "name": "@msgpack/msgpack-benchmark", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "update-dependencies": "npx rimraf node_modules/ package-lock.json ; npm install ; npm audit fix --force ; git restore package.json ; npm install" }, diff --git a/benchmark/profile-decode.ts b/benchmark/profile-decode.ts index 081ddab2..512d87e0 100644 --- a/benchmark/profile-decode.ts +++ b/benchmark/profile-decode.ts @@ -1,4 +1,4 @@ -import { encode, decode, decodeAsync } from "../src"; +import { encode, decode, decodeAsync } from "../src/index.ts"; // @ts-ignore import _ from "lodash"; const data = require("./benchmark-from-msgpack-lite-data.json"); diff --git a/benchmark/profile-encode.ts b/benchmark/profile-encode.ts index 6efcf017..245e71b5 100644 --- a/benchmark/profile-encode.ts +++ b/benchmark/profile-encode.ts @@ -1,4 +1,4 @@ -import { encode } from "../src"; +import { encode } from "../src/index.ts"; // @ts-ignore import _ from "lodash"; diff --git a/benchmark/string.ts b/benchmark/string.ts index b801394b..4f11f307 100644 --- a/benchmark/string.ts +++ b/benchmark/string.ts @@ -1,5 +1,5 @@ /* eslint-disable no-console */ -import { encode, decode } from "../src"; +import { encode, decode } from "../src/index.ts"; const ascii = "A".repeat(40000); const emoji = "🌏".repeat(20000); diff --git a/benchmark/sync-vs-async.ts b/benchmark/sync-vs-async.ts index 69819321..620438ef 100644 --- a/benchmark/sync-vs-async.ts +++ b/benchmark/sync-vs-async.ts @@ -1,12 +1,14 @@ -#!ts-node +#!/usr/bin/env node /* eslint-disable no-console */ -import { encode, decode, decodeAsync, decodeArrayStream } from "../src"; -import { writeFileSync, unlinkSync, readFileSync, createReadStream } from "fs"; -import { deepStrictEqual } from "assert"; +import { encode, decode, decodeAsync, decodeArrayStream } from "../src/index.ts"; +import { writeFileSync, unlinkSync, readFileSync, createReadStream } from "node:fs"; +import { deepStrictEqual } from "node:assert"; + +type Data = { id: number; score: number; title: string; content: string; createdAt: Date }; (async () => { - const data = []; + const data: Data[] = []; for (let i = 0; i < 1000; i++) { const id = i + 1; data.push({ diff --git a/benchmark/timestamp-ext.ts b/benchmark/timestamp-ext.ts index ba96a222..318b4451 100644 --- a/benchmark/timestamp-ext.ts +++ b/benchmark/timestamp-ext.ts @@ -1,4 +1,4 @@ -import { encode, decode } from "../src"; +import { encode, decode } from "../src/index.ts"; const data = new Array(100).fill(new Date());