Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
compose versus array versus merged
(version: 1)
Comparing performance of:
array vs compose vs merge
Created:
7 months ago
by:
Guest
Jump to the latest result
Script Preparation code:
function generateFunction () { let body = "x"; body += (Math.random () > 0.5) ? "*" : "+"; body += Math.floor (1 + Math.random () * 100); if (Math.random () > 0.75) body = "Math.min (" + body + "," + Math.floor (1 + Math.random () * 100) + ")"; const parameters = ["x"]; const expression = "return " + body + ";" const fun = new Function ("x", expression); fun.expression = expression fun.parameters = parameters; return fun; } const compose = (f, g) => x => g(f(x)); const funs = [generateFunction ()]; let funComposed = funs[0]; let expression = funComposed.expression; const len = 20; for (let i = 1 ; i < len ; i++) { const nfun = generateFunction (); expression = nfun.expression.replace ("return ", "x = ") + expression; console.log ("i", i, nfun); funs.push (nfun); funComposed = compose (nfun, funComposed); } const funMerged = new Function ("x", expression);
Tests:
array
let result = Math.floor (Math.random () * 100); for (let i = funs.length - 1 ; i >= 0 ; i--) result = funs[i] (result);
compose
let result = Math.floor (Math.random () * 100); result = funComposed (result);
merge
let result = Math.floor (Math.random () * 100); result = funMerged (result);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
array
compose
merge
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Browser/OS:
Chrome 140 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array
8870252.0 Ops/sec
compose
5611128.0 Ops/sec
merge
65281628.0 Ops/sec
Related benchmarks:
new functions
asdfasdffdas
+ '' vs .toString() v5 rand
Function vs dynamic function vs strict dynamic function
JavaScript String Starts/Ends With String Comparisons - Playground
Function vs () =>
Array of strings | Some vs Includes
Array of strings | Some vs Includes (+ spread)
compose versus array
Comments
Confirm delete:
Do you really want to delete benchmark?