compose implementation

JavaScript performance comparison

Test case created by yanglin5689446

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const TEST_NUMBER = 100000
  const result = []

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
recompose version
const compose = (...funcs) =>
  funcs.reduce((a, b) => (...args) => a(b(...args)), arg => arg)

const f = compose(parseInt, Math.exp, Math.log)

for(let i = 0 ;i < TEST_NUMBER; i ++)result.push(f(i))
pending…
redux version
function compose(...funcs) {
  if (funcs.length === 0) {
    return arg => arg
  }

  if (funcs.length === 1) {
    return funcs[0]
  }

  return funcs.reduce((a, b) => (...args) => a(b(...args)))
}

const f = compose(parseInt, Math.exp, Math.log)

for(let i = 0 ;i < TEST_NUMBER; i ++)result.push(f(i))
pending…
lodash flow
function compose(...funcs) {
  const length = funcs ? funcs.length : 0
  return function(...args) {
    let index = length - 1
    let result = length ? funcs[index].apply(this, args) : args[0]
    while (--index >= 0) {
      result = funcs[index].call(this, result)
    }
    return result
  }
}

const f = compose(parseInt, Math.exp, Math.log)

for(let i = 0 ;i < TEST_NUMBER; i ++)result.push(f(i))
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 Comments