@@ -46,36 +46,29 @@ const mod = {
46
46
} ;
47
47
48
48
function main ( { noAssert, millions, buf, type } ) {
49
- const len = millions * 1e6 ;
50
49
const clazz = buf === 'fast' ? Buffer : require ( 'buffer' ) . SlowBuffer ;
51
50
const buff = new clazz ( 8 ) ;
52
51
const fn = `write${ type || 'UInt8' } ` ;
53
52
54
53
if ( / I n t / . test ( fn ) )
55
- benchInt ( buff , fn , len , noAssert ) ;
54
+ benchInt ( buff , fn , millions , noAssert ) ;
56
55
else
57
- benchFloat ( buff , fn , len , noAssert ) ;
56
+ benchFloat ( buff , fn , millions , noAssert ) ;
58
57
}
59
58
60
- function benchInt ( buff , fn , len , noAssert ) {
59
+ function benchInt ( buff , fn , millions , noAssert ) {
61
60
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
- ` ) ;
67
61
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 ) ;
70
66
}
71
67
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 ) {
78
69
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 ) ;
81
74
}
0 commit comments