Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
ES6 vs Lodash range
(version: 0)
Benchmark.js
Comparing performance of:
ES6 Array.from vs Lodash rrange
Created:
6 years ago
by:
Guest
Go to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js"></script>
Tests:
ES6 Array.from
const a = Array.from( { length: 6 - 2 + 1 }, (_, ndx) => ndx + 2 )
Lodash rrange
const a = _.range(2, 6+1)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
ES6 Array.from
Lodash rrange
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Lodash rrange
53.9M/s
ES6 Array.from
5.8M/s
View exact numbers
Test name
Executions per second
✓
Lodash rrange
53,924,052 Ops/sec
ES6 Array.from
5,770,339 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the test cases and explain what's being tested. **Overview** The benchmark measures the performance of two approaches: using JavaScript's built-in `Array.from` method (ES6) versus using the `_.range` function from the Lodash library. The goal is to determine which approach is faster, more efficient, or has better performance characteristics. **Test Cases** There are two test cases: 1. **ES6 Array.from**: This test case uses JavaScript's built-in `Array.from` method to create an array with a specified length and initial value. 2. **Lodash `range`**: This test case uses the Lodash library's `_.range` function to achieve the same result as the ES6 `Array.from` method. **Library and Its Purpose** The Lodash library is a popular utility belt for JavaScript developers. In this context, the `_` prefix is used to access internal functions from the library. The `_.range` function generates an array of numbers within a specified range (in this case, from 2 to 6 inclusive). **Special JS Feature/Syntax** None of these test cases use any special JavaScript features or syntax that would be unique to specific browsers or environments. **Comparison and Pros/Cons** The two approaches have different characteristics: * **ES6 `Array.from`**: + Uses JavaScript's built-in `Array.from` method, which is a simple and efficient way to create an array. + Pros: Easy to understand, straightforward implementation, and highly optimized by browsers. + Cons: May not be as performant as other approaches, especially for large datasets. * **Lodash `_range`**: + Uses the Lodash library's `_.range` function, which is a convenient way to generate arrays with specific ranges. + Pros: Convenient and easy to use, can be more flexible than JavaScript's built-in methods. + Cons: Adds an additional dependency on the Lodash library, may have performance overhead due to the library's complexity. **Other Alternatives** Other approaches to create arrays could include: * Using `Array.prototype.fill()` or `Array.prototype.set()` to fill an existing array with values. * Using a simple loop to push values onto an array. * Using other libraries like Underscore.js, Ramda, or Fastify's built-in utility functions. However, these alternatives may not be as straightforward or optimized as the two approaches being compared here. **Benchmark Result Interpretation** The benchmark result shows that the Lodash `_range` function is slightly faster than the ES6 `Array.from` method in this particular test case. However, the difference is relatively small (approximately 30%), and the results may vary depending on the specific use case, dataset size, and browser/OS combination. It's essential to note that benchmarking can be complex and influenced by many factors, including the specific hardware, software configuration, and runtime environment.
Related benchmarks
Comparing performance of native .length and Lodash _.isEmpty
isEmpty vs. vanilla
native find vs lodash _.find..
lodash get vs es6
array find vs some vs lodash
Comments
Confirm delete:
Do you really want to delete benchmark?