@@ -21,6 +21,21 @@ const bench = common.createBenchmark(main, {
2121 n : [ 1e6 ] ,
2222} , { flags : [ '--expose-internals' ] } ) ;
2323
24+ function getConverter ( converter ) {
25+ switch ( converter ) {
26+ case 'octet' :
27+ return { bitLength : 8 } ;
28+ case 'unsigned short' :
29+ return { bitLength : 16 } ;
30+ case 'unsigned long' :
31+ return { bitLength : 32 } ;
32+ case 'long long' :
33+ return { bitLength : 64 , signedness : 'signed' } ;
34+ default :
35+ throw new Error ( `Unsupported converter: ${ converter } ` ) ;
36+ }
37+ }
38+
2439function getInput ( input ) {
2540 switch ( input ) {
2641 case 'integer' :
@@ -45,18 +60,18 @@ function getInput(input) {
4560}
4661
4762function main ( { n, converter, input } ) {
48- const { converters } = require ( 'internal/webidl' ) ;
49- const convert = converters [ converter ] ;
63+ const { convertToInt } = require ( 'internal/webidl' ) ;
64+ const { bitLength , signedness } = getConverter ( converter ) ;
5065 const { value, options } = getInput ( input ) ;
5166
5267 let noDead ;
5368 bench . start ( ) ;
5469 if ( options === undefined ) {
5570 for ( let i = 0 ; i < n ; i ++ )
56- noDead = convert ( value ) ;
71+ noDead = convertToInt ( value , bitLength , signedness ) ;
5772 } else {
5873 for ( let i = 0 ; i < n ; i ++ )
59- noDead = convert ( value , options ) ;
74+ noDead = convertToInt ( value , bitLength , signedness , options ) ;
6075 }
6176 bench . end ( n ) ;
6277
0 commit comments