Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Convert boolean to number
(version: 1)
May useful for some bit calculation that require high performance.
Comparing performance of:
+ vs Number call vs ? : vs if vs Number
Created:
9 months ago
by:
Registered User
Go to the latest result
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);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
+
Number call
? :
if
Number
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser/OS:
Firefox 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
+
1K/s
? :
964/s
if
962/s
Number
520/s
Number call
377/s
View exact numbers
Test name
Executions per second
✓
+
1,423 Ops/sec
? :
964 Ops/sec
if
962 Ops/sec
Number
520 Ops/sec
Number call
377 Ops/sec
Related benchmarks
Get max from an array of numbers (Math.max vs. iteration) V3
Compare the ways to convert String to Number in JS
Reduce vs Filter and Map
int to string convertation
Set/Map symbol vs Obj vs String vs Number
Compare the ways to convert String to Number in JS +
abs vs ** 2 vs math.pow
Comments
Confirm delete:
Do you really want to delete benchmark?