@@ -3,14 +3,96 @@ var util = require('util');
33
44var common = require ( '../common.js' ) ;
55
6- var bench = common . createBenchmark ( main , { n : [ 5e6 ] } ) ;
7-
8- function main ( conf ) {
9- var n = conf . n | 0 ;
6+ const opts = {
7+ showHidden : { showHidden : true } ,
8+ colors : { colors : true } ,
9+ none : undefined
10+ } ;
11+ var bench = common . createBenchmark ( main , {
12+ n : [ 2e6 ] ,
13+ method : [
14+ 'Object' ,
15+ 'Object_empty' ,
16+ 'Object_deep_ln' ,
17+ 'String' ,
18+ 'String_complex' ,
19+ 'String_boxed' ,
20+ 'Date' ,
21+ 'Set' ,
22+ 'Error' ,
23+ 'Array' ,
24+ 'TypedArray' ,
25+ 'TypedArray_extra'
26+ ] ,
27+ option : Object . keys ( opts )
28+ } ) ;
1029
30+ function benchmark ( n , obj , options ) {
1131 bench . start ( ) ;
1232 for ( var i = 0 ; i < n ; i += 1 ) {
13- util . inspect ( { a : 'a' , b : 'b' , c : 'c' , d : 'd' } ) ;
33+ util . inspect ( obj , options ) ;
1434 }
1535 bench . end ( n ) ;
1636}
37+
38+ function main ( { method, n, option } ) {
39+ var obj ;
40+ const options = opts [ option ] ;
41+ switch ( method ) {
42+ case 'Object' :
43+ benchmark ( n , { a : 'a' , b : 'b' , c : 'c' , d : 'd' } , options ) ;
44+ break ;
45+ case 'Object_empty' :
46+ benchmark ( n , { } , options ) ;
47+ break ;
48+ case 'Object_deep_ln' :
49+ if ( options )
50+ options . depth = Infinity ;
51+ obj = { first :
52+ { second :
53+ { third :
54+ { a : 'first' ,
55+ b : 'second' ,
56+ c : 'third' ,
57+ d : 'fourth' ,
58+ e : 'fifth' ,
59+ f : 'sixth' ,
60+ g : 'seventh' } } } } ;
61+ benchmark ( n , obj , options || { depth : Infinity } ) ;
62+ break ;
63+ case 'String' :
64+ benchmark ( n , 'Simple string' , options ) ;
65+ break ;
66+ case 'String_complex' :
67+ benchmark ( n , 'This string\nhas to be\tescaped!' , options ) ;
68+ break ;
69+ case 'String_boxed' :
70+ benchmark ( n , new String ( 'string' ) , options ) ;
71+ break ;
72+ case 'Date' :
73+ benchmark ( n , new Date ( ) , options ) ;
74+ break ;
75+ case 'Set' :
76+ obj = new Set ( [ 5 , 3 ] ) ;
77+ benchmark ( n , obj , options ) ;
78+ break ;
79+ case 'Error' :
80+ benchmark ( n , new Error ( 'error' ) , options ) ;
81+ break ;
82+ case 'Array' :
83+ benchmark ( n , Array ( 20 ) . fill ( ) . map ( ( _ , i ) => i ) , options ) ;
84+ break ;
85+ case 'TypedArray' :
86+ obj = new Uint8Array ( Array ( 50 ) . fill ( ) . map ( ( _ , i ) => i ) ) ;
87+ benchmark ( n , obj , options ) ;
88+ break ;
89+ case 'TypedArray_extra' :
90+ obj = new Uint8Array ( Array ( 50 ) . fill ( ) . map ( ( _ , i ) => i ) ) ;
91+ obj . foo = 'bar' ;
92+ obj [ Symbol ( 'baz' ) ] = 5 ;
93+ benchmark ( n , obj , options ) ;
94+ break ;
95+ default :
96+ throw new Error ( `Unsupported method "${ method } "` ) ;
97+ }
98+ }
0 commit comments