Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Option[Double]: box vs unbox fix
(version: 0)
Comparing performance of:
box vs unbox
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
function None() { } None.prototype.tag = 0; const none = new None(); function Some(payload) { this.payload = payload; } Some.prototype.tag = 1; var box = []; var unbox = []; for (let i = 0; i < 1000; i++) { box.push(i % 2 == 0 ? none : new Some(i * Math.PI)); unbox.push(i % 2 == 0 ? undefined : i * Math.PI); } function square(i) { return i * i }
Tests:
box
for (let i of box) { if (i.tag === 1) { square(i.payload) } }
unbox
for (let i of unbox) { if (i !== undefined) { square(i) } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
box
unbox
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser/OS:
Chrome 129 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
box
80181.2 Ops/sec
unbox
18153.4 Ops/sec
Related benchmarks:
Array.prototype.push vs Array.prototype.push.apply
Array.prototype.push vs Array.prototype.push.apply1
Array .push() vs .unshift() multiple
Array .push() vs .unshift() |
Array.prototype.push vs Array.prototype.shift
Comments
Confirm delete:
Do you really want to delete benchmark?