Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
ramda-transducer-push
(version: 0)
Using push instead of append
Comparing performance of:
Array(map + filter) vs ramda(map + filter) vs ramda-transducer(map + filter)
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://rawgit.com/ramda/ramda/master/dist/ramda.js"></script>
Script Preparation code:
var ids = Array.from({ length: 10000 }, (_, index) => index + 1) var isPositive = i => i % 2 === 0
Tests:
Array(map + filter)
ids.map(R.identity).filter(isPositive).map(R.inc)
ramda(map + filter)
R.pipe( R.map(R.identity), R.filter(isPositive), R.map(R.inc) )(ids)
ramda-transducer(map + filter)
const transform = R.pipe( R.map(R.identity), R.filter(isPositive), R.map(R.inc) ) R.transduce( transform, (xs, x) => (xs.push(x), xs), [], ids, );
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Array(map + filter)
ramda(map + filter)
ramda-transducer(map + filter)
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 17_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1.2 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 17 on iOS 17.1.2
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array(map + filter)
4965.8 Ops/sec
ramda(map + filter)
5015.9 Ops/sec
ramda-transducer(map + filter)
5209.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested, compared, and the pros/cons of each approach. **Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided JSON represents a benchmark for testing the performance of different approaches for transforming arrays using the Ramda library. **Script Preparation Code** The script preparation code includes two variables: ```javascript var ids = Array.from({ length: 10000 }, (_, index) => index + 1) var isPositive = i => i % 2 === 0 ``` Here, `ids` is an array of 10,000 elements, each starting from 1. The `isPositive` function checks whether a number is even (i.e., divisible by 2). **Benchmark Definition** The benchmark definition consists of three test cases: 1. **Array(map + filter)**: This test case uses the native JavaScript `map()` and `filter()` methods to transform the `ids` array. ```javascript ids.map(R.identity).filter(isPositive).map(R.inc) ``` 2. **ramda(map + filter)**: This test case uses Ramda's `R.pipe()` function to chain together three transformations: * `R.map(R.identity)` applies an identity function to each element in the array. * `R.filter(isPositive)` filters out elements that are not even. * `R.map(R.inc)` increments each remaining element by 1. ```javascript R.pipe( R.map(R.identity), R.filter(isPositive), R.map(R.inc) )(ids) ``` 3. **ramda-transducer(map + filter)**: This test case uses Ramda's `R.transduce()` function to apply a transformation to the `ids` array using a custom reducer: ```javascript const transform = R.pipe( R.map(R.identity), R.filter(isPositive), R.map(R.inc) ) R.transduce( transform, (xs, x) => (xs.push(x), xs), [], ids, ); ``` **What's Being Tested** The benchmark is testing the performance of three different approaches for transforming arrays: 1. **Native JavaScript**: Using native `map()` and `filter()` methods. 2. **Ramda: `R.pipe()`**: Chaining transformations using Ramda's `R.pipe()` function. 3. **Ramda: `R.transduce()`**: Applying a transformation to an array using Ramda's `R.transduce()` function. **Pros/Cons of Each Approach** Here's a brief summary: 1. **Native JavaScript**: * Pros: Fast, lightweight, and widely supported. * Cons: May not be as efficient as other approaches, especially for large datasets. 2. **Ramda: `R.pipe()`**: * Pros: Chaining transformations can lead to more efficient code, reduces overhead of function calls. * Cons: Can be less readable than other approaches, may require more memory allocation for intermediate results. 3. **Ramda: `R.transduce()`**: * Pros: Can be more efficient than `R.pipe()` for large datasets, as it avoids creating intermediate arrays. * Cons: Can lead to higher memory usage due to the use of a reducer function. **Other Considerations** The benchmark also includes information about the device platform (Mobile Safari 17), operating system (iOS 17.1.2), and execution frequency per second for each test case. **Alternatives** Some alternative approaches that could be tested include: * Using other functional programming libraries like Lodash or Underscore.js * Implementing custom reducers or transform functions using JavaScript's `reduce()` method * Comparing the performance of different array data structures, such as using an array with a custom iterator
Related benchmarks:
Spread operator vs Array.push vs array[lastIndex]
Spread or Push
test map lodash vs array
Adding to an array with push.apply vs spread
spread or push on large array
Comments
Confirm delete:
Do you really want to delete benchmark?