Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Raw vs lodaah
(version: 0)
Comparing performance of:
lodash vs raw
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 nums = [ [123, 64, 27], [1, 64, 48], [15, 4, 49], [51, 64, 48], [112, 23, 12], [38, 27] ]
Tests:
lodash
_(nums).flatten().groupBy(x=>x).sortBy(x=>x.length).map(_.head).reverse().value()
raw
var ids = {}; nums.forEach((stems) => stems.forEach((statementId) => { typeof ids[statementId] === "undefined" ? (ids[statementId] = 1) : ids[statementId]++; }) ) Object.entries(ids) .sort((a, b) => b[1] - a[1]) .map(x => x[0])
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash
raw
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 dive into the world of JavaScript microbenchmarks! **Benchmark Definition** The benchmark measures two different approaches to processing an array of numbers: using Lodash and a custom implementation. **Script Preparation Code** The script preparation code defines an array `nums` containing multiple sub-arrays, each with varying lengths. This array will be used as input for both the Lodash approach and the custom implementation. ```javascript var nums = [ [123, 64, 27], [1, 64, 48], [15, 4, 49], [51, 64, 48], [112, 23, 12], [38, 27] ]; ``` **Html Preparation Code** The HTML preparation code includes a reference to the Lodash library, which will be used for the benchmark. ```html <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script> ``` **Individual Test Cases** There are two test cases: 1. **Lodash** The first test case measures the performance of using Lodash to flatten, group by length, sort, and extract the head of each element in the `nums` array. ```javascript _(nums).flatten().groupBy(x=>x).sortBy(x=>x.length).map(_.head).reverse().value() ``` 2. **Raw** The second test case measures the performance of a custom implementation to achieve the same result as above: ```javascript var ids = {}; nums.forEach((stems) => { stems.forEach((statementId) => { typeof ids[statementId] === "undefined" ? (ids[statementId] = 1) : ids[statementId]++; }) }); Object.entries(ids) .sort((a, b) => b[1] - a[1]) .map(x => x[0]); ``` **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as: * Array manipulation (e.g., `flatten()`, `groupBy()`) * String manipulation (e.g., `sortBy()` in this case, but it's not used directly) * Object manipulation (e.g., `Object.entries()` and `map()`) In the context of this benchmark, Lodash is used to simplify the array processing pipeline. **Special JS feature/Syntax: None** There are no special JavaScript features or syntax used in these benchmarks. The focus is on comparing the performance of different approaches to achieve a specific result. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: * **Lodash**: Pros: + Simplifies array processing pipeline + Provides efficient implementations for common tasks (e.g., flattening, grouping) Cons: + Adds an external dependency (the Lodash library) + May incur overhead due to loading the library * **Raw**: Pros: + No external dependencies + More control over the implementation Cons: + Requires more manual effort and code maintenance **Other Alternatives** If you're interested in exploring other approaches, here are a few options: 1. **PureScript**: A statically typed, functional programming language that can be used for array processing tasks. 2. **TypeScript**: A superset of JavaScript that adds optional static typing, which can help improve code maintainability and performance. 3. **Array methods only**: You could try rewriting the benchmark using only native JavaScript array methods (e.g., `map()`, `forEach()`) without relying on any external libraries. Keep in mind that these alternatives might not be as efficient or convenient to use as Lodash, but they can provide a different perspective on array processing tasks.
Related benchmarks:
Ramda map vs Array.map vs Lodash map
lodash slice
Last Lodash Test
native slice vs lodash slice
lodash range vs Array.from vs keys() + spread 234das
Comments
Confirm delete:
Do you really want to delete benchmark?