Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Sequence Methods (Lodash vs Array)
(version: 0)
Comparing performance of:
Lodash vs Native Array
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Script Preparation code:
var personListA = [ { id: 1, name: "Thompson Gregory", age: 24 }, { id: 2, name: "Orr Mcdonald", age: 37 }, { id: 3, name: "Patterson Cline", age: 36 }, { id: 4, name: "Ryan Roy", age: 26 }, { id: 5, name: "Johnston Foreman", age: 36 }, { id: 6, name: "Bowers Cortez", age: 29 }, { id: 7, name: "Bernard Pena", age: 38 }, { id: 8, name: "Gladys Spears", age: 26 }, { id: 9, name: "Pittman Cain", age: 40 }, { id: 10, name: "Carver Wall", age: 26 }, { id: 11, name: "Mara Massey", age: 37 }, { id: 12, name: "Fletcher Peck", age: 20 }, { id: 13, name: "Bentley Moran", age: 34 }, { id: 14, name: "Ellison Witt", age: 33 } ] var personListB = [{ id: 15, name: "Freida Ramsey", age: 35 }, { id: 16, name: "Hines Zimmerman", age: 27 }, { id: 17, name: "Miranda Gilliam", age: 31 }, { id: 18, name: "Alejandra Dunlap", age: 29 }, { id: 19, name: "Lynnette Sawyer", age: 39 }, { id: 20, name: "Katy Adams", age: 33 }, { id: 21, name: "Howe Wilcox", age: 21 }, { id: 22, name: "Paige Holmes", age: 32 }, { id: 23, name: "Mable Estrada", age: 34 }, { id: 24, name: "York Lopez", age: 36 }, { id: 25, name: "Kris Mejia", age: 29 }, { id: 26, name: "Carlson Payne", age: 27 }, { id: 27, name: "Staci Flores", age: 34 }, { id: 28, name: "Eloise Lowe", age: 25 }, { id: 29, name: "Lyons Hicks", age: 30 }, { id: 30, name: "Goodwin Castro", age: 31 }]
Tests:
Lodash
var uniquePersons = _.chain(personListA) .concat(personListB) .uniqBy((person) => person.age) .orderBy( (person) => [person.age, person.id], ["desc", "desc"] ) .value();
Native Array
var uniquePersons = [...personListA, ...personListB] /** Avoid duplicate, filter by unique age */ .filter((person, index, all) => all.findIndex((p) => p.age === person.age) === index) /** Sort by age in descending order */ .sort((a, b) => a.age - b.age);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash
Native Array
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 break down the benchmark and explain what is being tested. **Benchmark Test Cases** The test cases are comparing two approaches: 1. **Native Array**: This approach uses native JavaScript array methods to achieve the same result as Lodash. Specifically, it uses `filter` and `sort` methods. 2. **Lodash**: This approach uses the popular utility library Lodash to perform the same operation. **What is being tested?** The benchmark is testing the performance of these two approaches in terms of execution speed. The test cases are comparing the number of executions per second (ExecutionsPerSecond) for each approach on a specific device and browser configuration. **Options Compared** In this case, there is only one option compared: Lodash vs Native Array. **Pros and Cons of Each Approach** * **Native Array**: Pros: + Lightweight and fast + No external dependencies or libraries required Cons: + Can be less readable and maintainable due to its simplicity + May not provide the same level of abstraction as Lodash * **Lodash**: Pros: + Provides a higher level of abstraction and readability + Offers a wide range of utility functions that can simplify code Cons: + Requires an external library dependency + Can be slower due to the overhead of loading the library **Benchmark Results** The latest benchmark results show that: * **Native Array**: 535231.5 executions per second (Chrome 117, Desktop, Mac OS X 10.15.7) * **Lodash**: 23050.3359375 executions per second (Chrome 117, Desktop, Mac OS X 10.15.7) The results suggest that the Native Array approach is significantly faster than Lodash on this specific device and browser configuration. It's worth noting that these results may vary depending on the specific use case, input data, and other factors. Additionally, while Native Array may be faster in this particular test, it's often more important to prioritize code readability and maintainability over raw performance.
Related benchmarks:
lodash_array_objects
lodash_array_objects_2
Test-BC
array find vs object key search
Comments
Confirm delete:
Do you really want to delete benchmark?