Skip to content

Commit 44dcb7b

Browse files
committed
bench: always use Buffer for JSON stuff
1 parent a804e13 commit 44dcb7b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ profile-decode:
3131
node --prof-process --preprocess -j isolate-*.log | npx flamebearer
3232

3333
benchmark:
34-
npx ts-node benchmark/benchmark-from-msgpack-lite.ts
34+
npx node -r ts-node/register benchmark/benchmark-from-msgpack-lite.ts
3535
@echo
3636
node benchmark/msgpack-benchmark.js
3737

benchmark/benchmark-from-msgpack-lite.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ var buf, obj;
4242

4343
if (JSON) {
4444
buf = bench('buf = Buffer.from(JSON.stringify(obj));', JSON_stringify, data);
45-
buf = bench('buf = JSON.stringify(obj);', JSON.stringify, data);
46-
obj = bench('obj = JSON.parse(buf);', JSON.parse, buf);
45+
obj = bench('obj = JSON.parse(buf.toString("utf-8"));', JSON_parse, buf);
4746
runTest(obj);
4847
}
4948

@@ -100,10 +99,14 @@ if (notepack) {
10099
runTest(obj);
101100
}
102101

103-
function JSON_stringify(src: any) {
102+
function JSON_stringify(src: any): Buffer {
104103
return Buffer.from(JSON.stringify(src));
105104
}
106105

106+
function JSON_parse(json: Buffer): any {
107+
return JSON.parse(json.toString("utf-8"));
108+
}
109+
107110
function bench(name: string, func: (...args: any[]) => any, src: any) {
108111
if (argv.length) {
109112
var match = argv.filter(function(grep) {

0 commit comments

Comments
 (0)