If vs Number constructor

Benchmark created on


Preparation HTML

		

Setup

const source = Array(10_000).fill(0).map(() => Math.random() * 1_000_000_000).map(x => (x | 0) % 2 === 0);

Test runner

Ready to run.

Testing in
TestOps/sec
if
let sum = 0;


for (const e of source) { if (e) { sum += 2; } else { sum += 1; } }
ready
Constructor
let sum = 0;


for (const e of source) { sum += Number(e) + 1; }
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.