jlongster / transducers.js

A small library for generalized transformation of data (inspired by Clojure's transducers)
BSD 2-Clause "Simplified" License
1.73k stars 54 forks source link

improve isArray check #10

Closed stefanpenner closed 9 years ago

stefanpenner commented 9 years ago

given:

sequence(compose(
  cat,
  map(square),
  filter(odd),
  take(20)
), range(0, 1000)
);

the improvement in node 0.11.14 was from about 425,000 op/s to 515,000 op/s

 v8: '3.26.33'
 node: '0.11.14'
stefanpenner commented 9 years ago

checking on the refactoring branch

stefanpenner commented 9 years ago

refactoring seems to run ^^ at about 373,000 op/s

jlongster commented 9 years ago

I've been testing a map->map->filter->filter sequence:

    seq(
      t.compose(
        t.map(function(x) { return x + 10; }),
        t.map(function(x) { return x * 2; }),
        t.filter(function(x) { return x % 5 === 0; }),
        t.filter(function(x) { return x % 2 === 0; })
      ),
      arr
    );

And on larger arrays (10000) the refactoring branch is a bit faster, but you're right on smaller arrays it is slower, and it's because of the closure overhead. I will convert everything to objects and we should see some crazy good speed.

Thanks for this PR, some of those utility functions definitely could be improved.

stefanpenner commented 9 years ago

@jlongster nice, keep up the good work. I'm unsure when, but I'll try to contribute more benchmarks.