Skip to content

Commit b17e533

Browse files
committed
benchmark: add json buffer config
1 parent c3e4ac2 commit b17e533

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

benchmark/json/json-parser.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
'use strict';
22
const { readFile } = require('node:fs/promises');
33
const common = require('../common.js');
4-
const { parse } = require('node:json');
4+
const { parse, parseFromBuffer } = require('node:json');
55
const path = require('node:path');
66

77
const configs = {
88
n: [1024],
9+
encoding: ['utf-8', 'buffer'],
910
};
1011

1112
const bench = common.createBenchmark(main, configs);
1213

1314
async function main(conf) {
14-
bench.start();
15+
const fn = conf.encoding === 'buffer' ? parseFromBuffer : parse;
16+
17+
const enconding = conf.encoding === 'buffer' ? undefined : conf.encoding;
18+
const json = await readFile(path.join(__dirname, 'twitter.json'), enconding);
1519

16-
const json = await readFile(path.join(__dirname, 'twitter.json'), 'utf-8');
20+
bench.start();
1721

1822
for (let i = 0; i < conf.n; i++) {
19-
parse(json);
23+
fn(json);
2024
}
2125

2226
bench.end(conf.n);

0 commit comments

Comments
 (0)