File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const common = require ( '../common.js' ) ;
4+
5+ const bench = common . createBenchmark ( main , {
6+ method : [ 'normal' , 'destructureObject' ] ,
7+ millions : [ 100 ]
8+ } ) ;
9+
10+ function runNormal ( n ) {
11+ var i = 0 ;
12+ var o = { x : 0 , y : 1 } ;
13+ bench . start ( ) ;
14+ for ( ; i < n ; i ++ ) {
15+ /* eslint-disable no-unused-vars */
16+ var x = o . x ;
17+ var y = o . y ;
18+ var r = o . r || 2 ;
19+ /* eslint-enable no-unused-vars */
20+ }
21+ bench . end ( n / 1e6 ) ;
22+ }
23+
24+ function runDestructured ( n ) {
25+ var i = 0 ;
26+ var o = { x : 0 , y : 1 } ;
27+ bench . start ( ) ;
28+ for ( ; i < n ; i ++ ) {
29+ /* eslint-disable no-unused-vars */
30+ var { x, y, r = 2 } = o ;
31+ /* eslint-enable no-unused-vars */
32+ }
33+ bench . end ( n / 1e6 ) ;
34+ }
35+
36+ function main ( conf ) {
37+ const n = + conf . millions * 1e6 ;
38+
39+ switch ( conf . method ) {
40+ case 'normal' :
41+ runNormal ( n ) ;
42+ break ;
43+ case 'destructureObject' :
44+ runDestructured ( n ) ;
45+ break ;
46+ default :
47+ throw new Error ( 'Unexpected method' ) ;
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments