blob: ccb9498a7eddb758d0ff342d95c7be03dab46e56 [file] [log] [blame]
const run = new Function("init", "num", `
function value() { return 'v'; }
noInline(value);
const calc = val => {
let c = 0;
for (let v = val; v; v >>>= 1) c += v & 1;
return val * 2 + val / 2 + c;
}
class A {
constructor(x) { this._v = x; }
set v(x) { this._v = x; }
get v() { return this._v; }
}
class B extends A {
set v(x) { super[value()] = x; }
get v() { return calc(super[value()]); }
}
const bench = (init, num) => {
let arr = [];
for (let i = 0; i != num; ++i) arr.push(new B(init));
for (let i = 0; i != num; ++i) arr[i].v += i;
let sum = 0;
for (let i = 0; i != num; ++i) sum += arr[i].v;
};
bench(init, num);
`);
run(2, 10000);
run(1 << 30, 10000);
run(42.2, 10000);
run(42.5e10, 10000);