File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 11'use strict' ;
22const { readFile } = require ( 'node:fs/promises' ) ;
33const common = require ( '../common.js' ) ;
4- const { parse } = require ( 'node:json' ) ;
4+ const { parse, parseFromBuffer } = require ( 'node:json' ) ;
55const path = require ( 'node:path' ) ;
66
77const configs = {
88 n : [ 1024 ] ,
9+ encoding : [ 'utf-8' , 'buffer' ] ,
910} ;
1011
1112const bench = common . createBenchmark ( main , configs ) ;
1213
1314async 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 ) ;
You can’t perform that action at this time.
0 commit comments