Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs vanila 3.3
(version: 0)
Comparing performance of:
Lodash vs Vanila vs Vanila2
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
function makeid(length) { var result = ''; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var charactersLength = characters.length; for ( var i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } function uniqByTitle1(arr) { return [...arr.reduce((items, item) => { if (!items.has(item.title)) { items.set(item.title, item); } return items; }, new Map()).values()]; } function uniqByTitle2(arr) { const items = new Map(); for (const item of arr) { if (!items.has(item.title)) { items.set(item.title, item); } } return [...items.values()]; } var arr = []; for(var i = 0; i < 100000; i++){ arr.push({ title: makeid(20), }); }
Tests:
Lodash
_.uniqBy(arr, (item => item.title));
Vanila
uniqByTitle1(arr)
Vanila2
uniqByTitle2(arr)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash
Vanila
Vanila2
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 provided benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Definition** The website uses JavaScript microbenchmarks to compare performance of two approaches: 1. **Lodash**: A popular JavaScript utility library that provides functions for various tasks, including array manipulation. 2. **Vanilla** (also referred to as "Vanila2"): The built-in JavaScript functionality without using any external libraries. **Script Preparation Code** The script generates an array of 100,000 objects with a random title string. This array is used as the input data for the benchmark tests. **Html Preparation Code** A reference to Lodash library is included in the HTML code, which will be executed before running the benchmark tests. **Individual Test Cases** There are three test cases: 1. **Lodash**: The benchmark definition uses `_.uniqBy(arr, (item => item.title))`, where `arr` is the generated array and `(item => item.title)` is a callback function that extracts the title from each object. 2. **Vanilla 1** (`Vanila`): The benchmark definition is `uniqByTitle1(arr)`, which uses a similar approach as Lodash, but without any external library. 3. **Vanilla 2** (`Vanila2`): The benchmark definition is `uniqByTitle2(arr)`, which also uses a similar approach as Vanilla 1, but with a slightly different implementation. **Pros and Cons** * **Lodash**: Pros: + Provides a robust and well-maintained library for common tasks. + Reduces boilerplate code and improves readability. + Can be easily extended or customized. * Cons: + Adds external dependency (library) to the benchmark, which may introduce overhead. + May not provide optimal performance due to library bloat. * **Vanilla**: Pros: + Does not introduce any external dependencies, reducing overhead. + May provide better performance for simple use cases or when resources are limited. * Cons: + Requires more boilerplate code and manual implementation of common tasks. + May be less readable and maintainable. **Library: Lodash** Lodash is a popular JavaScript utility library that provides functions for various tasks, such as array manipulation, string processing, and object transformation. It's designed to make it easier to write efficient and effective code by providing pre-built functions for common tasks. The `uniqBy` function in the benchmark definition uses Lodash to create a unique array of objects based on a specified key (in this case, the "title" property). This approach reduces boilerplate code and improves readability. **Special JS Feature or Syntax** None mentioned.
Related benchmarks:
reduce-vs-uniqBy_2
uniqBy vs stringify performance
Create an array with unique values - Javascript Array.reduce/Array.indexOf vs Lodash Uniq
Create an array with unique values - Javascript Array.reduce/Array.indexOf vs Lodash Uniq vs custom fn
lodash uniq vs native uniqoififie3f02i409rfi23k
Comments
Confirm delete:
Do you really want to delete benchmark?