Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs Native // rh
(version: 0)
Comparing performance of:
Native vs lodash
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var infoEvents = { test1: [ 'test', 'test' ], test2: [ 'test', 'test' ], test3: [ 'hello', 'hi' ], test4: [ 'heheheheheheh', 'hahahahaha' ], test5: [ 'ba', 'boo' ] }; var exceptionEvents = { test1: [ 'test', 'test' ], test2: [ 'test', 'test' ], test3: [ 'hello', 'hi' ], test4: [ 'heheheheheheh', 'hahahahaha' ], test5: [ 'ba', 'boo' ] };
Tests:
Native
function getEvents() { const eventNamesAndCategories = [ ...Object.values(infoEvents), ...Object.values(exceptionEvents) ]; const eventNames = [], eventCategories = []; const seenCategories = new Set(); eventNamesAndCategories.forEach( event => { eventNames.push(`${event[1]}/${event[0]}`); if (!seenCategories.has(event[1])) { eventCategories.push(event[1]); seenCategories.add(event[1]); } }); return; }
lodash
function getEvents() { const eventNamesAndCategories = [ ..._.map(infoEvents), ..._.map(exceptionEvents) ]; const eventNames = _(eventNamesAndCategories).map(nc => `${nc[1]}/${nc[0]}`).uniq().value(), eventCategories = _(eventNamesAndCategories).map(nc => nc[1]).uniq().value(); return; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native
lodash
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'd be happy to explain what's being tested in the provided JSON benchmark. **Overview** The benchmark is designed to compare the performance of two approaches: using native JavaScript (i.e., without any additional libraries) and using Lodash, a popular utility library for JavaScript. The test case involves generating event names from two separate objects (`infoEvents` and `exceptionEvents`) by mapping over them with various methods. **What's being tested** The benchmark is testing the performance of the following operations: 1. **Mapping**: Applying a function to each element of an array (using `_map(infoEvents)` and `_map(exceptionEvents)`) 2. **Uniquing**: Removing duplicates from an array (using `uniq()` on the mapped arrays) 3. **Concatenation**: Combining strings with slashes (`/${}`) **Options being compared** Two options are being compared: 1. **Native JavaScript**: Using native JavaScript functions to perform the mapping, unquencing, and concatenation operations. 2. **Lodash**: Using Lodash's `map()`, `uniq()`, and string concatenation methods to perform the same operations. **Pros and Cons of each approach** Here are some pros and cons of each approach: * **Native JavaScript**: + Pros: No additional dependencies, potentially faster execution (since no extra library is loaded) + Cons: More verbose code, may require more manual error handling * **Lodash**: + Pros: Less verbose code, built-in functionality for common tasks, potentially easier to maintain + Cons: Additional dependency required, may be slower due to overhead of loading the library **Other considerations** When using Lodash, it's worth noting that: * The `map()` function returns an array of mapped values, which is then passed to `uniq()` and `value()`. This could potentially lead to performance issues if the input arrays are very large. * The `_` alias for `lodash` is a common convention in JavaScript, but may not be familiar to all developers. **Library usage** In this benchmark, Lodash is used extensively. Lodash provides a set of utility functions that can simplify code and make it more readable, but also adds an extra layer of complexity due to the additional dependency required. If you were to rewrite this benchmark using native JavaScript, you would need to implement the `map()`, `uniq()`, and string concatenation operations yourself.
Related benchmarks:
Comparing performance of native some and Lodash _.some
String Constructor vs Lodash toString
Lodash some vs Native some
my test lodash vs native
array.find() vs. array.some() - big array version
Comments
Confirm delete:
Do you really want to delete benchmark?