@@ -7,19 +7,22 @@ const types = [
77 'UInt16BE' ,
88 'UInt32LE' ,
99 'UInt32BE' ,
10+ 'UIntLE' ,
11+ 'UIntBE' ,
1012 'Int8' ,
1113 'Int16LE' ,
1214 'Int16BE' ,
1315 'Int32LE' ,
1416 'Int32BE' ,
17+ 'IntLE' ,
18+ 'IntBE' ,
1519 'FloatLE' ,
1620 'FloatBE' ,
1721 'DoubleLE' ,
1822 'DoubleBE'
1923] ;
2024
2125const bench = common . createBenchmark ( main , {
22- noAssert : [ 'false' , 'true' ] ,
2326 buffer : [ 'fast' , 'slow' ] ,
2427 type : types ,
2528 millions : [ 1 ]
@@ -28,9 +31,9 @@ const bench = common.createBenchmark(main, {
2831const INT8 = 0x7f ;
2932const INT16 = 0x7fff ;
3033const INT32 = 0x7fffffff ;
31- const UINT8 = ( INT8 * 2 ) + 1 ;
32- const UINT16 = ( INT16 * 2 ) + 1 ;
33- const UINT32 = INT32 ;
34+ const INT48 = 0x7fffffffffff ;
35+ const UINT8 = 0xff ;
36+ const UINT16 = 0xffff ;
3437
3538const mod = {
3639 writeInt8 : INT8 ,
@@ -41,34 +44,57 @@ const mod = {
4144 writeUInt8 : UINT8 ,
4245 writeUInt16BE : UINT16 ,
4346 writeUInt16LE : UINT16 ,
44- writeUInt32BE : UINT32 ,
45- writeUInt32LE : UINT32
47+ writeUInt32BE : INT32 ,
48+ writeUInt32LE : INT32 ,
49+ writeUIntLE : INT8 ,
50+ writeUIntBE : INT16 ,
51+ writeIntLE : INT32 ,
52+ writeIntBE : INT48
4653} ;
4754
48- function main ( { noAssert, millions, buf, type } ) {
55+ const byteLength = {
56+ writeUIntLE : 1 ,
57+ writeUIntBE : 2 ,
58+ writeIntLE : 4 ,
59+ writeIntBE : 6
60+ } ;
61+
62+ function main ( { millions, buf, type } ) {
4963 const clazz = buf === 'fast' ? Buffer : require ( 'buffer' ) . SlowBuffer ;
5064 const buff = new clazz ( 8 ) ;
5165 const fn = `write${ type || 'UInt8' } ` ;
5266
53- if ( / I n t / . test ( fn ) )
54- benchInt ( buff , fn , millions , noAssert ) ;
67+ if ( ! / \d / . test ( fn ) )
68+ benchSpecialInt ( buff , fn , millions ) ;
69+ else if ( / I n t / . test ( fn ) )
70+ benchInt ( buff , fn , millions ) ;
5571 else
56- benchFloat ( buff , fn , millions , noAssert ) ;
72+ benchFloat ( buff , fn , millions ) ;
73+ }
74+
75+ function benchInt ( buff , fn , millions ) {
76+ const m = mod [ fn ] ;
77+ bench . start ( ) ;
78+ for ( var i = 0 ; i !== millions * 1e6 ; i ++ ) {
79+ buff [ fn ] ( i & m , 0 ) ;
80+ }
81+ bench . end ( millions ) ;
5782}
5883
59- function benchInt ( buff , fn , millions , noAssert ) {
84+ function benchSpecialInt ( buff , fn , millions ) {
6085 const m = mod [ fn ] ;
86+ const byte = byteLength [ fn ] ;
6187 bench . start ( ) ;
6288 for ( var i = 0 ; i !== millions * 1e6 ; i ++ ) {
63- buff [ fn ] ( i & m , 0 , noAssert ) ;
89+ buff [ fn ] ( i & m , 0 , byte ) ;
6490 }
6591 bench . end ( millions ) ;
6692}
6793
68- function benchFloat ( buff , fn , millions , noAssert ) {
94+ function benchFloat ( buff , fn , millions ) {
6995 bench . start ( ) ;
7096 for ( var i = 0 ; i !== millions * 1e6 ; i ++ ) {
71- buff [ fn ] ( i , 0 , noAssert ) ;
97+ buff [ fn ] ( i , 0 ) ;
7298 }
7399 bench . end ( millions ) ;
74100}
0 commit comments