Debian Codegraph @

js/src/jit-test/tests/basic/homogenous-literals.js

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