const a = 20;
const b = 40;
function diff (title, handler)
{
console.time(title);
for (let offset = 0; offset <= 100_000_000; ++offset)
{
handler();
}
console.timeEnd(title);
}
diff('math', () => (Math.abs(a + b) + Math.abs(a - b)) / 2);
diff('func', () => Math.max(a, b));
diff('if', () => a < b ? a : b);
To embed this project on your website, copy the following code and paste it into your website's HTML: