File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const fs = require ( 'fs' ) ;
3+ const path = require ( 'path' ) ;
4+ const common = require ( '../common.js' ) ;
5+
6+ const tmpdir = require ( '../../test/common/tmpdir' ) ;
7+ const benchmarkDirectory = path . join ( tmpdir . path , 'nodejs-benchmark-module' ) ;
8+
9+ const bench = common . createBenchmark ( main , {
10+ ext : [ '' , '.js' ] ,
11+ files : [ 1e3 ] ,
12+ cache : [ 'true' , 'false' ]
13+ } ) ;
14+
15+ function main ( { ext, cache, files } ) {
16+ tmpdir . refresh ( ) ;
17+ fs . mkdirSync ( benchmarkDirectory ) ;
18+ fs . writeFileSync (
19+ `${ benchmarkDirectory } /a.js` ,
20+ 'module.exports = {};'
21+ ) ;
22+ for ( var i = 0 ; i <= files ; i ++ ) {
23+ fs . mkdirSync ( `${ benchmarkDirectory } /${ i } ` ) ;
24+ fs . writeFileSync (
25+ `${ benchmarkDirectory } /${ i } /package.json` ,
26+ '{"main": "index.js"}'
27+ ) ;
28+ fs . writeFileSync (
29+ `${ benchmarkDirectory } /${ i } /index.js` ,
30+ `require('../a${ ext } ');`
31+ ) ;
32+ }
33+
34+ measureDir ( cache === 'true' , files ) ;
35+
36+ tmpdir . refresh ( ) ;
37+ }
38+
39+ function measureDir ( cache , files ) {
40+ var i ;
41+ if ( cache ) {
42+ for ( i = 0 ; i <= files ; i ++ ) {
43+ require ( `${ benchmarkDirectory } /${ i } ` ) ;
44+ }
45+ }
46+ bench . start ( ) ;
47+ for ( i = 0 ; i <= files ; i ++ ) {
48+ require ( `${ benchmarkDirectory } /${ i } ` ) ;
49+ }
50+ bench . end ( files ) ;
51+ }
You can’t perform that action at this time.
0 commit comments