File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const benchmark = require ( './2-benchmark.js' ) ;
4+
5+ const data = {
6+ a : 'abc' ,
7+ bcd : 'defg' ,
8+ efgh : 'hijklmn' ,
9+ ijk : 'opqrst' ,
10+ lmnopqrs : 'u' ,
11+ tvuwx : 'v' ,
12+ yz : 'xyz'
13+ } ;
14+
15+ function testForKeys ( ) {
16+ const a = Array ( 7 ) ;
17+ let i , key ;
18+ const keys = Object . keys ( data ) ;
19+ const len = keys . length ;
20+ for ( i = 0 ; i < len ; i ++ ) {
21+ key = keys [ i ] ;
22+ a [ i ] = data [ key ] ;
23+ }
24+ }
25+
26+
27+ function testForIn ( ) {
28+ const a = Array ( 7 ) ;
29+ let i = 0 ;
30+ for ( let key in data ) {
31+ a [ i ++ ] = data [ key ] ;
32+ }
33+ }
34+
35+ function testForInLet ( ) {
36+ const a = Array ( 7 ) ;
37+ let i = 0 ;
38+ let key ;
39+ for ( key in data ) {
40+ a [ i ++ ] = data [ key ] ;
41+ }
42+ }
43+
44+ function testForOf ( ) {
45+ const a = Array ( 7 ) ;
46+ let i = 0 ;
47+ let key , val ;
48+ const keys = Object . keys ( data ) ;
49+ const len = keys . length ;
50+ for ( key of keys ) {
51+ val = data [ key ] ;
52+ a [ i ++ ] = val ;
53+ }
54+ }
55+
56+ function testForOfLet ( ) {
57+ const a = Array ( 7 ) ;
58+ let i = 0 ;
59+ let key , val ;
60+ const keys = Object . keys ( data ) ;
61+ const len = keys . length ;
62+ for ( let key of keys ) {
63+ val = data [ key ] ;
64+ a [ i ++ ] = val ;
65+ }
66+ }
67+
68+ benchmark . do ( 1000000 , 5 , [
69+ testForKeys ,
70+ testForIn ,
71+ testForInLet ,
72+ testForOf ,
73+ testForOfLet
74+ ] ) ;
You can’t perform that action at this time.
0 commit comments