File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const util = require ( 'util' ) ;
4
+ const common = require ( '../common' ) ;
5
+ const v8 = require ( 'v8' ) ;
6
+ const bench = common . createBenchmark ( main , {
7
+ n : [ 1e6 ]
8
+ , type : [ 'string' ,
9
+ 'number' ,
10
+ 'object' ,
11
+ 'unknown' ,
12
+ 'no-replace' ]
13
+ } ) ;
14
+
15
+ const inputs = {
16
+ 'string' : [ 'Hello, my name is %s' , 'fred' ] ,
17
+ 'number' : [ 'Hi, I was born in %d' , 1942 ] ,
18
+ 'object' : [ 'An error occurred %j' , { msg : 'This is an error' , code : 'ERR' } ] ,
19
+ 'unknown' : [ 'hello %a' , 'test' ] ,
20
+ 'no-replace' : [ 1 , 2 ]
21
+ } ;
22
+
23
+ function main ( conf ) {
24
+ const n = conf . n | 0 ;
25
+ const type = conf . type ;
26
+
27
+ const input = inputs [ type ] ;
28
+
29
+ v8 . setFlagsFromString ( '--allow_natives_syntax' ) ;
30
+
31
+ util . format ( input [ 0 ] , input [ 1 ] ) ;
32
+ eval ( '%OptimizeFunctionOnNextCall(util.format)' ) ;
33
+ util . format ( input [ 0 ] , input [ 1 ] ) ;
34
+
35
+ bench . start ( ) ;
36
+ for ( var i = 0 ; i < n ; i ++ ) {
37
+ util . format ( input [ 0 ] , input [ 1 ] ) ;
38
+ }
39
+ bench . end ( n ) ;
40
+ }
You can’t perform that action at this time.
0 commit comments