Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash MapValue vs Pure JS
(version: 0)
Comparing performance of:
Lodash Test vs Pure JS Test
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
Script Preparation code:
function format_lodash(data) { return data.map(({ id, label, ...properties}) => { return { id, label, properties: _.mapValues(properties, v => v[0]) }; }); } function format_pure(data) { return data.map(({ id, label, ...properties}) => { for (let [key, value] of Object.entries(properties)) { properties[key] = value[0] } return { id, label, properties}; }); }
Tests:
Lodash Test
const input = [{ id: 1, label: 'label 1', property_1: ['prop_1'], property_2: ['prop_2'] }, { id: 2, label: 'label 2', property_3: ['prop_3'], property_4: ['prop_4'] } ] console.log(format_lodash(input))
Pure JS Test
const input = [{ id: 1, label: 'label 1', property_1: ['prop_1'], property_2: ['prop_2'] }, { id: 2, label: 'label 2', property_3: ['prop_3'], property_4: ['prop_4'] } ] console.log(format_lodash(input))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash Test
Pure JS Test
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15
Browser/OS:
Safari 18 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash Test
1436039.0 Ops/sec
Pure JS Test
1420876.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided JSON represents two JavaScript microbenchmarks: `Lodash MapValue vs Pure JS` and its two test cases, `Lodash Test` and `Pure JS Test`. The benchmarks aim to compare the performance of Lodash's `mapValues` function with a pure JavaScript implementation. **What is being tested?** The test cases provide input data in the following format: ```javascript [ { id: 1, label: 'label 1', property_1: ['prop_1'], property_2: ['prop_2'] }, { id: 2, label: 'label 2', property_3: ['prop_3'], property_4: ['prop_4'] } ] ``` The `mapValues` function is used to transform the properties of each object in the array. The benchmark compares the performance of two implementations: 1. Lodash's `mapValues` function, which is a part of the Lodash library. 2. A pure JavaScript implementation, which uses `Object.entries()` and `for...of` loop to achieve similar results. **Options compared** The options being compared are: * Use of Lodash's `mapValues` function vs. a pure JavaScript implementation * Performance: The benchmark measures the number of executions per second for each test case **Pros and Cons of different approaches** 1. **Lodash's `mapValues` function**: * Pros: + Provides a convenient and efficient way to map values in an object. + Part of a widely-used and well-maintained library (Lodash). * Cons: + Adds external dependency (Lodash library) which may slow down the benchmark. + May not be optimized for performance, especially when compared to pure JavaScript implementations. 2. **Pure JavaScript implementation**: * Pros: + No external dependencies, making it a self-contained test case. + Can be optimized for performance, as it is part of the benchmark itself. * Cons: + Requires manual implementation of the `mapValues` function, which can lead to errors or inefficiencies. **Library and syntax used** The Lodash library is used in the first test case. Specifically, the `mapValues` function is used to transform the properties of each object in the input array. There are no special JavaScript features or syntax used in this benchmark. However, note that the use of `Object.entries()` and `for...of` loop in the pure JavaScript implementation demonstrates modern JavaScript language features. **Alternatives** If you want to write similar benchmarks for other JavaScript libraries or functions, consider the following alternatives: * Use other JavaScript libraries like underscore.js or ramda.js instead of Lodash. * Compare different optimization techniques, such as caching or memoization. * Test performance with different input data types (e.g., arrays, objects, etc.) or sizes. Keep in mind that the choice of library and implementation will depend on the specific benchmarking goals and requirements.
Related benchmarks:
Object.keys vs lodash _.keys
lodash (v4.17.15) map vs Object.keys map
Lodash MapValue vs Pure JS [2.0]
array.map vs _.map
Comments
Confirm delete:
Do you really want to delete benchmark?