Created
January 26, 2019 22:36
-
-
Save rasmusvhansen/8ca56d7d02b169b2b0859dbbf7b669c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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