Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Rxjs several pipes vs one 100k
(version: 1)
Comparing performance of:
RxJS one pipe vs Several pipes
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://unpkg.com/rxjs@6.5.5/bundles/rxjs.umd.min.js'></script>
Script Preparation code:
var rawdata = Array.from(Array(100000).keys()) // 10k numbers 1,2,3,4,5...
Tests:
RxJS one pipe
let { from, Observable } = rxjs; let { flatMap, map, tap, toArray } = rxjs.operators; const data$ = from(rawdata) .pipe( map(values => { const finalValues = new Map(); values.map(value => value * 2) .filter(value => value % 3 === 0) .forEach(value => finalValues.set(value.toString(), value)) return finalValues; }) ) let data; data$.subscribe(d => data = d);
Several pipes
let { from, Observable } = rxjs; let { flatMap, map, tap, toArray } = rxjs.operators; const data$ = from(rawdata) .pipe( map(values => values.map(value => value * 2)), map(values => values.filter(value => value % 3 === 0)), map(values => { const finalValues = new Map(); values.forEach(value => finalValues.set(value.toString(), value)); return finalValues; }) ) let data; data$.subscribe(d => data = d);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
RxJS one pipe
Several pipes
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the provided benchmark and explain what is being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark compares the performance of using multiple pipes versus a single pipe in RXJS for filtering data. The input data consists of 100,000 numbers from 1 to 100,000. **Options Compared** Two options are compared: 1. **RxJS One Pipe**: This approach uses the `pipe()` method to chain together three `map()` operators: * First map: doubles each value (`values.map(value => value * 2)`). * Second map: filters values where the result is divisible by 3 (`values.filter(value => value % 3 === 0)`). * Third map: converts the resulting array into a Map (`values.forEach(value => finalValues.set(value.toString(), value))`). 2. **RxJS Several Pipes**: This approach uses three separate `pipe()` methods for each operation: * First pipe (map): doubles each value (`map(values => values.map(value => value * 2))`). * Second pipe (filter): filters values where the result is divisible by 3 (`map(values => values.filter(value => value % 3 === 0))`). * Third pipe (map): converts the resulting array into a Map (`map(values => values.forEach(value => finalValues.set(value.toString(), value)))`). **Pros and Cons** 1. **RxJS One Pipe**: * Pros: Less memory allocation and garbage collection overhead, as only one instance of the intermediate arrays is created. * Cons: More complex pipeline, potentially harder to understand and maintain. 2. **RxJS Several Pipes**: * Pros: Easier to understand and maintain, as each operation is separate and focused on its specific task. * Cons: More memory allocation and garbage collection overhead, as multiple instances of intermediate arrays are created. **Library Used** The benchmark uses the RXJS library, which is a popular reactive programming library for JavaScript. The `rxjs` module provides operators for working with observables, such as `map()`, `filter()`, and `pipe()`. **Special JS Feature/Syntax** This benchmark does not use any special JavaScript features or syntax, making it accessible to developers without deep knowledge of JavaScript. **Other Alternatives** If you need to optimize data processing in a reactive manner, consider the following alternatives: 1. **Lodash**: A popular utility library for functional programming tasks, including filtering and mapping. 2. **Preact**: A lightweight alternative to React, which also provides features for building reactive applications. 3. **RxJava**: A Java-based version of RXJS, designed for use in Android app development. Keep in mind that the choice of library or approach depends on your specific requirements and the nature of your project.
Related benchmarks:
Rxjs several pipes vs one 100k with entries v2
Rxjs several pipes vs one 100k without functional array functions at all
Rxjs several pipes vs one 100k without functional array functions at all qwerq
Rxjs several pipes vs one 100k without functional array functions at all 123sdfaasd
Comments
Confirm delete:
Do you really want to delete benchmark?