Page MenuHomePhorge

microbench_hoist.js
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

microbench_hoist.js

// Benchmark to test function declaration hoisting optimization
// The function contains "function" in strings/comments but no actual declarations
function processItem(item) {
// This comment mentions function declaration hoisting
// The word "function" appears here: function function function
let type = "function"; // string contains "function"
let desc = "This is a function test";
let x = item * 2;
let y = x + 1;
return y + type.length + desc.length;
}
const iterations = 200000;
console.log(`Running ${iterations} iterations...`);
let start = Date.now();
let result = 0;
for (let i = 0; i < iterations; i++) {
result += processItem(i);
}
console.log(`with "function" in body: ${Date.now() - start}ms (result: ${result})`);
// Compare with a function that doesn't have "function" anywhere
function processClean(item) {
let type = "method";
let desc = "This is a test";
let x = item * 2;
let y = x + 1;
return y + type.length + desc.length;
}
start = Date.now();
result = 0;
for (let i = 0; i < iterations; i++) {
result += processClean(i);
}
console.log(`without "function" in body: ${Date.now() - start}ms (result: ${result})`);

File Metadata

Mime Type
text/plain
Expires
Sun, May 3, 7:17 AM (53 m, 52 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
518945
Default Alt Text
microbench_hoist.js (1 KB)

Event Timeline