3 ms·
Tentative benchmark results have surfaced: https://github.com/thheller/transduce-bench https://github.com/thheller/transduce-bench Add salt according to taste.
by fnordsensei 12y ago
Tentative benchmark results have surfaced: https://github.com/thheller/transduce-bench https://github.com/thheller/transduce-bench
Add salt according to taste.
- mduerksen 12y agoThe benchmark is wrong atm, the compared functions do not yield the same result. (comp (map inc) (filter even?)) means filtering first, then incrementing. The opposite for (->> data (map inc) (filter even?) ... - which is not the same. And of course, it also means that the latter has to increment the double amount of numbers. EDIT: It was me who was wrong, thanks for the corrections. Pitfall successfully identified :)
- pyrtsa 12y agoNope, that's the funny feature of transducers. Like lenses in Haskell, transducers compose in reversed order. (sequence (comp (map inc) (filter even?)) (range 10)) ;;=> (2 4 6 8 10) (->> (range 10) (map inc) (filter even?)) ;;=> (2 4 6 8 10) Both test functions in transduce-bench return 250000500000.
- richhickey 12y agoIt seems counterintuitive, but composing transducers yields a reducing function that runs the transformation steps left->right. What you are composing is the reducing function transformations (right to left, ordinary composition), but their result, having been built inside-out, runs the steps outside-in. So (comp tx1 tx2...) runs in same order as (->> xs tx1 tx2...)