1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
// Copyright 2025 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// For-loop examples that we approximate as either large or small.
// Large loops that we'll determine as large:
for (const a = 0; a < 10000; a++) {
console.log("Large1");
}
for (const a = 0; a < 1e3; a++) {
console.log("Large2");
}
for (const a = -0.01e7; a < 0.01e7; a++) {
console.log("Large3");
}
for (const a = 0; 10000 >= a; a++) {
console.log("Large4");
}
for (const a = 1000; a != 0; a--) {
console.log("Large5");
}
for (const a = 1e3; 0 != a; a--) {
console.log("Large6");
}
for (const a = 29303.34; 124.2 != a; a -= 0.7) {
console.log("Large7");
}
for (const a = 0n; a < 3000000000000n; a++) {
console.log("Large8");
}
// Test that we internally don't make a mixed bigint/non-bigint computation.
for (const a = 0; a < 30000000000000000000000000n; a++) {
console.log("Large10");
}
// Not really large, but we still approximate it as large:
for (const a = 0; a < 10000; a += 1000) {
console.log("Large11");
}
// Small loops that we'll determine as small:
for (const a = 0; a < 10; a++) {
console.log("Small1");
}
for (const a = 0; a < 999; a++) {
console.log("Small2");
}
for (const a = 3; 0 != a; a--) {
console.log("Small3");
}
for (const a = 10000; a > 9100; a--) {
console.log("Small4");
}
// Large loops that we can't determine, so we approximate them
// as small.
const b = 10000;
for (const a = b; a > 0; a--) {
console.log("Small5");
}
for (const a = 10000, b = 10000; a > 0; a--) {
console.log("Small6");
}
const c = 0;
for (const a = 10000; a > c; a--) {
console.log("Small7");
}
for (const a = 10000; a > 0 && other; a--) {
console.log("Small8");
}
// Types and structures that we can't determine, hence small.
for (var str = "start"; str < "end"; str += "inc") {
console.log("Small9");
}
for (let a = []; a < [0, 1, 2]; a += [0]) {
console.log("Small10");
}
for (let {a} = 123; a < 10000; a++) {
console.log("Small11");
}
for (let a = !1; a < 10000; a++) {
console.log("Small12");
}
// Other stuff for code coverage.
let d = 0
for (; d < 10000; d++) {
console.log("Small13");
}
for (let a = 0;;) {
console.log("Small14");
}
for (;;) {
console.log("Small15");
}
for (call();call();call()) {
console.log("Small16");
}
|