File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ // Call fs.readFile over and over again really fast.
2+ // Then see how many times it got called.
3+ // Yes, this is a silly benchmark. Most benchmarks are silly.
4+
5+ var path = require ( 'path' ) ;
6+ var common = require ( '../common.js' ) ;
7+ var filename = path . resolve ( __dirname , '.removeme-benchmark-garbage' ) ;
8+ var fs = require ( 'fs' ) ;
9+
10+ var bench = common . createBenchmark ( main , {
11+ dur : [ 1 , 3 ] ,
12+ len : [ 1024 , 16 * 1024 * 1024 ] ,
13+ concurrent : [ 1 , 10 ]
14+ } ) ;
15+
16+ function main ( conf ) {
17+ var len = + conf . len ;
18+ try { fs . unlinkSync ( filename ) ; } catch ( e ) { }
19+ var data = new Buffer ( len ) ;
20+ data . fill ( 'x' ) ;
21+ fs . writeFileSync ( filename , data ) ;
22+ data = null ;
23+
24+ var reads = 0 ;
25+ bench . start ( ) ;
26+ setTimeout ( function ( ) {
27+ bench . end ( reads ) ;
28+ try { fs . unlinkSync ( filename ) ; } catch ( e ) { }
29+ } , + conf . dur * 1000 ) ;
30+
31+ function read ( ) {
32+ fs . readFile ( filename , afterRead ) ;
33+ }
34+
35+ function afterRead ( er , data ) {
36+ if ( er )
37+ throw er ;
38+
39+ if ( data . length !== len )
40+ throw new Error ( 'wrong number of bytes returned' ) ;
41+
42+ reads ++ ;
43+ read ( ) ;
44+ }
45+
46+ var cur = + conf . concurrent ;
47+ while ( cur -- ) read ( ) ;
48+ }
You can’t perform that action at this time.
0 commit comments