Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Convert boolean to number
May useful for some bit calculation that require high performance.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser:
Firefox 147
Operating system:
Windows
Device Platform:
Desktop
Date tested:
4 months ago
Test name
Executions per second
+
1423.5 Ops/sec
Number call
377.2 Ops/sec
? :
963.7 Ops/sec
if
962.4 Ops/sec
Number
520.5 Ops/sec
Script Preparation code:
const arr = Array.from({ length: 100000 }, () => Math.random() > 0.5);
Tests:
+
const converted = arr.map(v => +v);
Number call
const converted = arr.map(v => Number(v));
? :
const converted = arr.map(v => v ? 1 : 0);
if
const converted = arr.map(v => { if (v) return 1; else return 0; });
Number
const converted = arr.map(Number);