Skip to content

Commit 8e96e63

Browse files
authored
Merge pull request #287 from msgpack/gfx/fix_bench_scripts
chore: fix benchmark scripts for node, bun, and deno
2 parents cd7b03a + 5829619 commit 8e96e63

File tree

10 files changed

+20
-15
lines changed

10 files changed

+20
-15
lines changed

benchmark/benchmark-from-msgpack-lite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
22
// original: https://raw.githubusercontent.com/kawanet/msgpack-lite/master/lib/benchmark.js
33

4-
var msgpack_msgpack = require("../src");
4+
var msgpack_msgpack = require("../src/index.ts");
55

66
var msgpack_node = try_require("msgpack");
77
var msgpack_lite = try_require("msgpack-lite");

benchmark/decode-string.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
2-
import { utf8EncodeJs, utf8Count, utf8DecodeJs, utf8DecodeTD } from "../src/utils/utf8";
2+
import { utf8EncodeJs, utf8Count, utf8DecodeJs, utf8DecodeTD } from "../src/utils/utf8.ts";
33

44
// @ts-ignore
55
import Benchmark from "benchmark";

benchmark/encode-string.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
2-
import { utf8EncodeJs, utf8Count, utf8EncodeTE } from "../src/utils/utf8";
2+
import { utf8EncodeJs, utf8Count, utf8EncodeTE } from "../src/utils/utf8.ts";
33

44
// @ts-ignore
55
import Benchmark from "benchmark";

benchmark/key-decoder.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
/* eslint-disable no-console */
2-
import { utf8EncodeJs, utf8Count, utf8DecodeJs } from "../src/utils/utf8";
2+
import { utf8EncodeJs, utf8Count, utf8DecodeJs } from "../src/utils/utf8.ts";
3+
import { CachedKeyDecoder } from "../src/CachedKeyDecoder.ts";
4+
5+
import data from "./benchmark-from-msgpack-lite-data.json" with { type: "json" };
36

47
// @ts-ignore
58
import Benchmark from "benchmark";
6-
import { CachedKeyDecoder } from "../src/CachedKeyDecoder";
79

810
type InputType = {
911
bytes: Uint8Array;
1012
byteLength: number;
1113
str: string;
1214
};
1315

14-
const keys: Array<InputType> = Object.keys(require("./benchmark-from-msgpack-lite-data.json")).map((str) => {
16+
const keys: Array<InputType> = Object.keys(data).map((str) => {
1517
const byteLength = utf8Count(str);
1618
const bytes = new Uint8Array(new ArrayBuffer(byteLength));
1719
utf8EncodeJs(str, bytes, 0);

benchmark/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@msgpack/msgpack-benchmark",
33
"private": true,
44
"version": "0.0.0",
5+
"type": "module",
56
"scripts": {
67
"update-dependencies": "npx rimraf node_modules/ package-lock.json ; npm install ; npm audit fix --force ; git restore package.json ; npm install"
78
},

benchmark/profile-decode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { encode, decode, decodeAsync } from "../src";
1+
import { encode, decode, decodeAsync } from "../src/index.ts";
22
// @ts-ignore
33
import _ from "lodash";
44
const data = require("./benchmark-from-msgpack-lite-data.json");

benchmark/profile-encode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { encode } from "../src";
1+
import { encode } from "../src/index.ts";
22
// @ts-ignore
33
import _ from "lodash";
44

benchmark/string.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
2-
import { encode, decode } from "../src";
2+
import { encode, decode } from "../src/index.ts";
33

44
const ascii = "A".repeat(40000);
55
const emoji = "🌏".repeat(20000);

benchmark/sync-vs-async.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
#!ts-node
1+
#!/usr/bin/env node
22
/* eslint-disable no-console */
33

4-
import { encode, decode, decodeAsync, decodeArrayStream } from "../src";
5-
import { writeFileSync, unlinkSync, readFileSync, createReadStream } from "fs";
6-
import { deepStrictEqual } from "assert";
4+
import { encode, decode, decodeAsync, decodeArrayStream } from "../src/index.ts";
5+
import { writeFileSync, unlinkSync, readFileSync, createReadStream } from "node:fs";
6+
import { deepStrictEqual } from "node:assert";
7+
8+
type Data = { id: number; score: number; title: string; content: string; createdAt: Date };
79

810
(async () => {
9-
const data = [];
11+
const data: Data[] = [];
1012
for (let i = 0; i < 1000; i++) {
1113
const id = i + 1;
1214
data.push({

benchmark/timestamp-ext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { encode, decode } from "../src";
1+
import { encode, decode } from "../src/index.ts";
22

33
const data = new Array(100).fill(new Date());
44

0 commit comments

Comments
 (0)