Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Comparing lodash's times with Array.from
(version: 0)
Comparing performance of:
lodash times vs array.from
Created:
2 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:
var size = 10000;
Tests:
lodash times
_.times(size, index => `$${0 + index}`);
array.from
Array.from({length: size}, (_, index) => `$${0 + index}`);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash times
array.from
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/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash times
19446.0 Ops/sec
array.from
3917.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the Benchmark Definition and explore what is being tested. **Benchmark Overview** The benchmark compares the performance of two approaches: using Lodash's `times` function and creating an array with `Array.from`. The goal is to determine which approach is faster for a specific use case (creating an array of strings). **Lodash times Function** * **Library:** Lodash is a popular JavaScript utility library that provides various functions for tasks like string manipulation, array manipulation, and more. * **Purpose:** In this context, the `times` function generates an array of values by repeating a provided callback function `size` number of times. **Array.from Method** * This method creates a new Array instance from an iterable (in this case, an object with a `length` property). * It takes two arguments: the iterable and a callback function to transform each element. * The callback function in this benchmark is a simple string concatenation that returns `$${0 + index}`, where `index` is the current iteration number. **Comparison** The two approaches are being compared: 1. Lodash's `times` function generates an array of strings by calling a callback function for each iteration, whereas the `Array.from` method creates an array and then applies the callback function to each element. 2. The `times` function is likely to be faster because it avoids creating unnecessary arrays or objects. **Pros and Cons** * Lodash's `times` function: + Pros: Efficient way to generate an array of strings, potentially faster than `Array.from`. + Cons: Requires the inclusion of Lodash in the script, which might add overhead. * `Array.from` method: + Pros: Creates a new Array instance and applies the callback function to each element, which can be more intuitive for some developers. + Cons: May create unnecessary intermediate objects or arrays. **Other Considerations** * The benchmark is run on Chrome 126 (Mac OS X 10.15.7) Desktop. * The `ExecutionsPerSecond` metric provides a measure of how many times the code was executed per second, giving an idea of performance. * The Raw UA String and Browser information might provide additional context about the testing environment. **Alternatives** Other approaches to generate an array of strings could be used: 1. `for...of` loop: A simple iterative approach that can be more readable but might not be as efficient as `Array.from`. 2. `Array.prototype.push`: Adding elements to an existing array is often slower than creating a new array. 3. Other libraries or frameworks (e.g., Backbone.js, Ember.js) may provide similar functions for generating arrays of strings. Keep in mind that the performance difference between these approaches might be negligible for most use cases, and other factors like code readability, maintainability, and scalability should also be considered when choosing an approach.
Related benchmarks:
Lodash Times vs Array.from callback
lodash times vs Array.from
isEmpty Test
lodash times vs new Array() && for loop
Comments
Confirm delete:
Do you really want to delete benchmark?