@@ -46,36 +46,29 @@ const mod = {
4646} ;
4747
4848function main ( { noAssert, millions, buf, type } ) {
49- const len = millions * 1e6 ;
5049 const clazz = buf === 'fast' ? Buffer : require ( 'buffer' ) . SlowBuffer ;
5150 const buff = new clazz ( 8 ) ;
5251 const fn = `write${ type || 'UInt8' } ` ;
5352
5453 if ( / I n t / . test ( fn ) )
55- benchInt ( buff , fn , len , noAssert ) ;
54+ benchInt ( buff , fn , millions , noAssert ) ;
5655 else
57- benchFloat ( buff , fn , len , noAssert ) ;
56+ benchFloat ( buff , fn , millions , noAssert ) ;
5857}
5958
60- function benchInt ( buff , fn , len , noAssert ) {
59+ function benchInt ( buff , fn , millions , noAssert ) {
6160 const m = mod [ fn ] ;
62- const testFunction = new Function ( 'buff' , `
63- for (var i = 0; i !== ${ len } ; i++) {
64- buff.${ fn } (i & ${ m } , 0, ${ noAssert } );
65- }
66- ` ) ;
6761 bench . start ( ) ;
68- testFunction ( buff ) ;
69- bench . end ( len / 1e6 ) ;
62+ for ( var i = 0 ; i !== millions * 1e6 ; i ++ ) {
63+ buff [ fn ] ( i & m , 0 , noAssert ) ;
64+ }
65+ bench . end ( millions ) ;
7066}
7167
72- function benchFloat ( buff , fn , len , noAssert ) {
73- const testFunction = new Function ( 'buff' , `
74- for (var i = 0; i !== ${ len } ; i++) {
75- buff.${ fn } (i, 0, ${ noAssert } );
76- }
77- ` ) ;
68+ function benchFloat ( buff , fn , millions , noAssert ) {
7869 bench . start ( ) ;
79- testFunction ( buff ) ;
80- bench . end ( len / 1e6 ) ;
70+ for ( var i = 0 ; i !== millions * 1e6 ; i ++ ) {
71+ buff [ fn ] ( i , 0 , noAssert ) ;
72+ }
73+ bench . end ( millions ) ;
8174}
0 commit comments