Page MenuHomePhorge

bench_jit_missing_params.cjs
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

bench_jit_missing_params.cjs

const now = () => (typeof performance !== 'undefined' && performance.now ? performance.now() : Date.now());
function readScale() {
if (typeof process === 'undefined' || !process || !process.argv) return 1;
const raw = Number(process.argv[2]);
return Number.isFinite(raw) && raw > 0 ? raw : 1;
}
const SCALE = readScale();
const REPEATS = 5;
function bench(name, rounds, fn) {
fn(Math.max(1, (rounds / 8) | 0));
const samples = [];
let out = 0;
for (let i = 0; i < REPEATS; i++) {
const t0 = now();
out = fn(rounds);
samples.push(now() - t0);
}
let best = samples[0];
let sum = 0;
for (let i = 0; i < samples.length; i++) {
if (samples[i] < best) best = samples[i];
sum += samples[i];
}
const avg = sum / samples.length;
console.log(`${name}: best ${best.toFixed(2)} ms, avg ${avg.toFixed(2)} ms, out ${out}`);
return out;
}
function hotMissingParamWrite(rounds) {
function f(val, options) {
options = options || {};
if (typeof val === 'number') return options.long ? 2 : 3;
return 0;
}
let sum = 0;
for (let i = 0; i < rounds; i++) sum += f(i);
return sum;
}
function hotPresentParamWrite(rounds) {
function f(val, options) {
options = options || {};
if (typeof val === 'number') return options.long ? 2 : 3;
return 0;
}
const shared = {};
let sum = 0;
for (let i = 0; i < rounds; i++) sum += f(i, shared);
return sum;
}
function hotNoParamWrite(rounds) {
function f(val, options) {
if (!options) options = {};
if (typeof val === 'number') return options.long ? 2 : 3;
return 0;
}
const shared = {};
let sum = 0;
for (let i = 0; i < rounds; i++) sum += f(i, shared);
return sum;
}
function hotLocalWrite(rounds) {
function f(val, options) {
let opts = options || {};
if (typeof val === 'number') return opts.long ? 2 : 3;
return 0;
}
let sum = 0;
for (let i = 0; i < rounds; i++) sum += f(i);
return sum;
}
const rounds = 8_000_000 * SCALE;
console.log(`jit missing-parameter benchmark (${rounds} rounds)`);
bench('missing param write', rounds, hotMissingParamWrite);
bench('present param write', rounds, hotPresentParamWrite);
bench('no param write', rounds, hotNoParamWrite);
bench('local alias write', rounds, hotLocalWrite);

File Metadata

Mime Type
application/javascript
Expires
Sat, May 2, 8:36 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
541342
Default Alt Text
bench_jit_missing_params.cjs (2 KB)

Event Timeline