homogenous-literals.js (986B)
1 function processNoProperty(a) { 2 var total = 0; 3 for (var i = 0; i < a.length; i++) { 4 var sa = a[i]; 5 for (var j = 0; j < sa.length; j++) 6 total += sa[j]; 7 } 8 assertEq(total, 22); 9 } 10 11 var literalArray = [ 12 [1,2,3,4], 13 [1.5,2.5,3.5,4.5] 14 ]; 15 16 var jsonArray = JSON.parse(`[ 17 [1,2,3,4], 18 [1.5,2.5,3.5,4.5] 19 ]`); 20 21 for (var i = 0; i < 1000; i++) { 22 processNoProperty(literalArray); 23 processNoProperty(jsonArray); 24 } 25 26 function processWithProperty(a) { 27 var total = 0; 28 for (var i = 0; i < a.length; i++) { 29 var sa = a[i].p; 30 for (var j = 0; j < sa.length; j++) 31 total += sa[j]; 32 } 33 assertEq(total, 22); 34 } 35 36 var literalPropertyArray = [ 37 {p:[1,2,3,4]}, 38 {p:[1.5,2.5,3.5,4.5]} 39 ]; 40 41 var jsonPropertyArray = JSON.parse(`[ 42 {"p":[1,2,3,4]}, 43 {"p":[1.5,2.5,3.5,4.5]} 44 ]`); 45 46 for (var i = 0; i < 1000; i++) { 47 processWithProperty(literalPropertyArray); 48 processWithProperty(jsonPropertyArray); 49 }