Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lo vs native
(version: 0)
Comparing performance of:
lodash vs native
Created:
7 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 src='https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.0/moment.min.js'></script>
Script Preparation code:
var arr = [{"id":"5c3daf0b31cdc200074fc122","name":"~!@#$%^&*()_+`-=,.\/;'\\[]:\"|<>?{}","state":"prelive","layout":{"interactivity":"none"},"startDate":1547546400000,"duration":60,"archived":false,"securityData":{"registrationAccess":false},"theme":{"id":"5c330dbf31cdc2002a00f5e9","name":"Theme Example (1)","logoFileUrl":null,"faviconFileUrl":null,"audioOnlyFileUrl":null}},{"id":"5c330dbf31cdc2002a00f5ee","name":"Webcast Example (1)","state":"prelive","layout":{"interactivity":"none"},"startDate":4143180000,"archived":false,"securityData":{"registrationAccess":false},"theme":{"id":"5c330dbf31cdc2002a00f5e9","name":"Theme Example (1)","logoFileUrl":null,"faviconFileUrl":null,"audioOnlyFileUrl":null}},{"id":"5c330dbf31cdc2002a00f5f4","name":"Webcast Example (2)","state":"live","layout":{"interactivity":"none"},"startDate":1465196400,"archived":false,"securityData":{"registrationAccess":false},"theme":{"id":"5c330dbf31cdc2002a00f5ea","name":"Theme Example (2)","logoFileUrl":null,"faviconFileUrl":null,"audioOnlyFileUrl":null}},{"id":"5c330dbf31cdc2002a00f5f5","name":"Webcast Example (3)","state":"postlive","layout":{"interactivity":"none"},"startDate":1456260000,"archived":false,"securityData":{"registrationAccess":false},"theme":{"id":"5c330dbf31cdc2002a00f5eb","name":"Theme Example (3)","logoFileUrl":null,"faviconFileUrl":null,"audioOnlyFileUrl":null}}];
Tests:
lodash
let sortedByYears = sortListByDate(arr, 'YYYY', 'year'); _.map(sortedByYears, (byYearItem) => ({ year: byYearItem.year, months: sortListByDate(byYearItem.webcasts, 'MMMM', 'month') }) ); function sortListByDate(list, dateFormat, newProp) { const sortByYears = sortByDateFormat(list, dateFormat) .map(mappingBydate(dateFormat, newProp)); return _.chain(sortByYears) .groupBy(newProp) .map((webcasts, propName) => ({ [newProp]: propName, webcasts })) .reverse() .value(); } function dateFormatter(format) { return (webcast) => moment(webcast.startDate).format(format); } function mappingBydate(format, name) { return (webcast) => ({ ...webcast, [name]: dateFormatter(format)(webcast) }); } function sortByDateFormat(list, format) { return _.sortBy(list, dateFormatter(format)); }
native
const result = []; let currentYear; let currentYearIndex = -1; let currentMonth; let currentMonthIndex = -1; arr.forEach((webcast) => { const year = moment(webcast.startDate).format('YYYY'); const month = moment(webcast.startDate).format('MMMM'); if (!currentYear || year !== currentYear['year']) { currentYearIndex++; currentYear = { year, 'months': {} }; result[currentYearIndex] = currentYear; } if (!currentMonth || month !== currentMonth['month']) { currentMonthIndex++; currentMonth = { month, 'webcasts': [] }; currentYear['months'][currentMonthIndex] = currentMonth; } currentMonth['webcasts'].push(webcast); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash
native
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'm excited to dive into the details of this benchmark! **What is being tested?** The provided JSON represents two individual test cases: `lo` (using Lodash) and `native` (using native JavaScript). The benchmark tests how efficiently these two approaches can process a list of objects with specific properties. **Options compared:** 1. **Lodash (`lo`)**: A popular JavaScript library for functional programming, offering various utility functions. 2. **Native JavaScript (`native`)**: The built-in JavaScript engine used by modern web browsers, which also has its own set of built-in methods and data structures. **Pros and Cons:** * **Lodash (lo)**: + Pros: Provides a standardized way to perform common operations, such as sorting, filtering, and mapping. This can lead to more concise and readable code. + Cons: Requires additional memory for the library itself, which might impact performance in very large datasets or when running out of memory. * **Native JavaScript (native)**: + Pros: Optimized for performance and doesn't require additional memory for a library. Can be faster for very large datasets or when resources are limited. + Cons: Requires more code to achieve the same results, which can make it less readable. **Library usage:** In this benchmark, Lodash is used extensively in both test cases (`lo`). The `lodash` object provides various functions like `sortBy`, `map`, and `_chain`. These functions are utilized to process the input array `arr` and produce a sorted result. **Special JavaScript features/syntax:** * **Moment.js**: A popular library for working with dates. In this benchmark, it's used to format the `startDate` property of each webcast object into different formats (e.g., 'YYYY', 'MMMM'). Moment.js is not specifically required for the benchmark but makes the code more readable. **Other alternatives:** If you need to perform similar operations without Lodash, you could use other JavaScript libraries like: * **Underscore.js**: Another popular functional programming library that offers many of the same functions as Lodash. * **Ramda**: A functional programming library with a strong focus on immutability and recursion. For native JavaScript implementation, you might consider using built-in methods like `Array.prototype.sort()`, `Array.prototype.map()`, or `Array.prototype.reduce()` to perform similar operations. However, these would likely require more code and might not be as concise as the Lodash implementations. I hope this explanation helps!
Related benchmarks:
Json parse
clone json 2
JSON clone
JSON.stringify vs structuredClone with large Objects 2
Comments
Confirm delete:
Do you really want to delete benchmark?