Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
ramda lens vs shallow performance check
(version: 1)
Comparing performance of:
evolve assoc vs lens prop vs assocPath vs lens path
Created:
6 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
Script Preparation code:
var object = { some: { prop1: 2, prop2: 3, } } var propLens = R.lensProp('some'); var pathLens = R.lensPath(['some', 'prop1']);
Tests:
evolve assoc
var result = R.evolve({ some: R.assoc('prop1', 10) }, object)
lens prop
var result = R.over(propLens, R.assoc('prop1', 10), object)
assocPath
var result = R.assocPath(['some', 'prop1'], 10, object)
lens path
var result = R.set(pathLens, 10, object)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
evolve assoc
lens prop
assocPath
lens path
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):
I'll break down the provided benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Overview** The provided JSON represents a benchmark test created using MeasureThat.net. The benchmark compares the performance of different approaches to perform updates on an object using various lenses from the Ramda library. **Test Cases** There are four individual test cases: 1. **evolve assoc**: Verifies the performance of `R.evolve` with `R.assoc`. 2. **lens prop**: Compares the performance of `R.over(propLens, R.assoc('prop1', 10), object)` using a lens (`propLens`) to update an object's property. 3. **assocPath**: Tests the performance of `R.assocPath(['some', 'prop1'], 10, object)`, which uses a path (array of keys) to update an object's property. 4. **lens path**: Verifies the performance of `R.set(pathLens, 10, object)` using a lens (`pathLens`) to update an object's property. **Libraries and Features** The benchmark utilizes Ramda, a popular functional programming library for JavaScript. Specifically: * `R.evolve`: A function that creates an evolution function, which allows you to create functions that modify objects. * `R.assoc`: An association function that takes two arguments: the key-value pair and an object. * `propLens` and `pathLens`: Lenses from Ramda that represent a path or property in the object. **Options Compared** The benchmark compares the performance of different approaches: 1. **Direct Property Update**: Updating properties directly on the object using the dot notation (`object.some.prop1 = 10`). 2. **Lens-Based Updates**: Using lenses to update properties (e.g., `R.over(propLens, R.assoc('prop1', 10), object)`). **Pros and Cons** Here's a brief summary of the pros and cons for each approach: * **Direct Property Update**: + Pros: Simple, efficient, and widely supported. + Cons: May not be as flexible or reusable as lens-based approaches. * **Lens-Based Updates**: + Pros: More flexible, reusable, and composable than direct property updates. + Cons: Can introduce additional overhead due to the use of lenses. **Other Considerations** When choosing between these approaches, consider the following: 1. **Readability**: Direct property updates might be more readable for simple cases, while lens-based updates can lead to more concise and expressive code. 2. **Reusability**: Lens-based updates can make your code more reusable and modular, as you can easily compose lenses to update different parts of an object. 3. **Performance**: The benchmark results suggest that the direct property update approach might be faster in this specific case. **Alternatives** If you're looking for alternatives to Ramda or lens-based updates, consider: 1. **Lodash**: A popular utility library that provides functions similar to Ramda's lenses and associations. 2. ** Immutable.js**: A library that helps you create immutable data structures using objects and updates. 3. **ES6 Object Updates**: You can use the `Object.assign()` method or object destructuring to update properties on an object. I hope this explanation helps!
Related benchmarks:
ramda clone vs spread
ramda toPairs vs. Object.entries
Immer vs shallow vs ramda lens (nested structure)
Ramda vs. VanillaJS - Find an object by prop
Comments
Confirm delete:
Do you really want to delete benchmark?