Skip to content

Instantly share code, notes, and snippets.

@rasmusvhansen
Created January 26, 2019 22:36
Show Gist options
  • Save rasmusvhansen/8ca56d7d02b169b2b0859dbbf7b669c2 to your computer and use it in GitHub Desktop.
Save rasmusvhansen/8ca56d7d02b169b2b0859dbbf7b669c2 to your computer and use it in GitHub Desktop.
const source = Array(1000000).fill(1).map((_, i) => Math.random());
console.time('array chaining');
const arrayResult = source
.map(n => n * 2)
.filter(n => n > 0.5)
.reduce((m, c) => Math.max(m, c));
console.timeEnd('array chaining'); // 310.901ms
console.time('rxjs transducer');
const transducerResult = transducer(source)(
map(n => n * 2),
filter(n => n > 0.5),
max()
);
console.timeEnd('rxjs transducer'); // 47.573ms
console.log(arrayResult === transducerResult[0]); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment