Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
compose versus array versus merged versus meged use strict
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
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:
Chrome 140
Operating system:
Windows
Device Platform:
Desktop
Date tested:
7 months ago
Test name
Executions per second
array
8889621.0 Ops/sec
compose
5504024.5 Ops/sec
merge
61552516.0 Ops/sec
merge use strict
61545336.0 Ops/sec
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); const funMergedUseStrict = new Function ("x", "'use strict';" + 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);
merge use strict
let result = Math.floor (Math.random () * 100); result = funMergedUseStrict (result);