Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Ramda complex map over large array
(version: 13)
Comparing performance of:
Without propagate vs Propagate vs Without propagate2 vs Propagate DEEP
Created:
7 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var data = [] for (var i = 1; i <= 50000; i++) { data.push({ id: i, value: 'test', otherValue: 'other test' }) } var realData = { toPropagate: { attributes: { id: { name: '1id' }, value: { name: '2value' }, id: { name: '3id' }, value: { name: '4value' }, id: { name: '5id' }, value: { name: '6value' }, id: { name: '7id' }, value: { name: '8value' }, id: { name: '9id' }, value: { name: '10value' }, id: { name: '11id' }, value: { name: '12value' }, id: { name: '13id' }, value: { name: '14value' }, id: { name: '15id' }, value: { name: '16value' }, id: { name: '17id' }, value: { name: '18value' }, id: { name: '19id' }, value: { name: '20value' }, id: { name: '21id' }, value: { name: '22value' }, id: { name: '23id' }, value: { name: '24value' }, id: { name: '25id' }, value: { name: '26value' }, id: { name: '27id' }, value: { name: '28value' }, id: { name: '29id' }, value: { name: '30value' }, id: { name: '31id' }, value: { name: '32value' }, id: { name: '33id' }, value: { name: '34value' }, id: { name: '35id' }, value: { name: '36value' }, id: { name: '37id' }, value: { name: '38value' }, id: { name: '39id' }, value: { name: '40value' }, id: { name: '41id' }, value: { name: '42value' }, id: { name: '43id' }, value: { name: '44value' }, id: { name: '45id' }, value: { name: '46value' }, id: { name: '47id' }, value: { name: '48value' }, id: { name: '49id' }, value: { name: '50value' }, id: { name: '51id' }, value: { name: '52value' }, id: { name: '53id' }, value: { name: '54value' }, id: { name: '55id' }, value: { name: '56value' } } }, data } function propagate (realData) { return dataItem => { return R.assoc('propagated', realData.toPropagate, dataItem) } } function propagateDeep (realData) { return dataItem => { dataItem.propagated = _.cloneDeep(realData.toPropagate) return dataItem } } function propagateAll () { return R.pipe( R.prop('data'), R.map(propagate(realData)), data => { return R.assoc('data', data, realData) } )(realData) } function propagateAllDeep () { return R.pipe( R.prop('data'), R.map(propagateDeep(realData)), data => { return R.assoc('data', data, realData) } )(realData) } function doNotPropagate () { return realData }
Tests:
Without propagate
doNotPropagate()
Propagate
propagateAll()
Without propagate2
doNotPropagate()
Propagate DEEP
propagateAllDeep()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Without propagate
Propagate
Without propagate2
Propagate DEEP
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 benchmark and explain what's being tested, compared, and the pros/cons of each approach. **Benchmark Overview** The benchmark compares the performance of four functions that propagate data from one object to another: 1. `doNotPropagate()`: Returns the original data without any modifications. 2. `propagateAll()` : Uses Ramda's `R.pipe` function to apply a series of transformations to the data, including propagating it with `realData`. 3. `doNotPropagate()` (again): The same as the first one, but with a different name. 4. `propagateAllDeep()` : Similar to `propagateAll()`, but uses Lodash's `_` function for deep cloning instead of Ramda's `R.cloneDeep`. **Comparison** The benchmark compares the performance of these four functions on a single test case, which is `doNotPropagate()`. The results are: | Test Name | Executions Per Second | | --- | --- | | Without propagate2 | 3791123.25 | | Without propagate | 3780382.0 | | Propagate | 24.74095916748047 | | Propagate DEEP | 3.79672908782959 | **Interpretation** The results suggest that: * `doNotPropagate()` is the fastest, with an execution rate of over 379 million per second. * `propagateAll()` and `doNotPropagate()` are significantly slower, with execution rates of around 378 million and 24.7 million per second, respectively. * `propagateAllDeep()` is the slowest, with an execution rate of only around 3.8 million per second. **Reasons for differences** The main reasons for these performance differences are: * **Overhead**: Ramda's `R.pipe` function has some overhead due to its functional programming paradigm and the need to create a new function for each transformation. * **Deep cloning**: Lodash's `_` function uses a deep cloning algorithm, which can be more expensive than simple assignment or propagation. * **Function call overhead**: Each of these functions involves multiple function calls, which can introduce additional overhead. **Best practice** Based on the results, it seems that `doNotPropagate()` is the most efficient approach for this specific use case. However, if deep cloning is necessary, using `propagateAllDeep()` might be acceptable if the performance trade-off is justified by the benefits of deep cloning.
Related benchmarks:
Array.map vs For Loop
BM | For + Push vs Map
Object spread vs New map
Object spread vs New map entries
lodash flatten vs array.flatMap corrected transform
Comments
Confirm delete:
Do you really want to delete benchmark?