Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
declare test
(version: 8)
Comparing performance of:
func2 vs func1
Created:
2 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var func1 = function(obj) { if (obj !== undefined) { return obj.x; } } var func2 = function(obj) { if (obj) { return obj.x; } } var ar1 = []; var ar2 = []; for (let i = 0; i < 1e5; i++) { ar1.push(Math.random() < 0.5 ? void 0 : {'x': Math.random()}); ar2.push(Math.random() < 0.5 ? void 0 : {'x': Math.random()}); } for (let i = 0; i < 1e3; ++i) { func1(Math.random() < 0.5 ? void 0 : {'x': Math.random()}); func2(Math.random() < 0.5 ? void 0 : {'x': Math.random()}); }
Tests:
func2
for (let i = 0; i < 1e5; ++i) { func2(ar1[i]); }
func1
for (let i = 0; i < 1e5; ++i) { func1(ar1[i]); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
func2
func1
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
func2
65.2 Ops/sec
func1
34.3 Ops/sec
Related benchmarks:
Unique elements of two arrays
Array push or set
Map vs Array.
Spread Operator VS Array.prototype.slice() VS Array.prototype.slice(0)
Spread Operator VS Array.prototype.slice() VS Array.prototype.map()
Comments
Confirm delete:
Do you really want to delete benchmark?