Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.map vs array.map for UInt8Array - part 2
(version: 0)
Comparing performance of:
_.map vs array.map
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.core.js"></script>
Script Preparation code:
var cs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var values = new Uint8Array(32); window.crypto.getRandomValues(values);
Tests:
_.map
_.map(values, v => cs[v % cs.length]).join('');
array.map
Array.from(values).map(v => cs[v % cs.length]).join('')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.map
array.map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 Edg/146.0.0.0
Browser/OS:
Chrome 146 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.map
1529857.8 Ops/sec
array.map
694814.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested. **Benchmark Definition** The benchmark measures the performance of two approaches to iterate over an array: `_map` from the Lodash library and `array.map`. The test is designed to compare these two methods for iterating over a `Uint8Array` (an array of unsigned 8-bit integers). **Options Compared** 1. **Lodash's `_map`**: This function applies a given function to each element of an array, returning a new array with the transformed values. 2. **Plain `array.map`**: This is a built-in JavaScript method that applies a given function to each element of an array, returning a new array with the transformed values. **Pros and Cons** 1. **Lodash's `_map`**: * Pros: Often more efficient than plain `array.map`, especially for large arrays, as it avoids creating a temporary array and uses optimized implementations under the hood. * Cons: May have additional overhead due to the function creation process and potential dependencies on external libraries (in this case, Lodash). 2. **Plain `array.map`**: * Pros: Lightweight, easy to understand, and always available in modern browsers without any external dependencies. * Cons: Can be slower for large arrays due to the temporary array creation step. **Library Used** The benchmark uses the Lodash library, specifically its `_map` function. Lodash is a popular utility library that provides various functional programming helpers, including `_.map`. The use of Lodash's `_map` allows the test to compare its performance with the built-in `array.map` method. **Other Considerations** * Both approaches are suitable for smaller arrays, but as the array size increases, Lodash's `_map` may be more efficient. * The benchmark measures the number of executions per second, which is a common metric for measuring performance. * To get accurate results, it's essential to ensure that all browsers and environments use the same version of JavaScript and Lodash (if applicable). **Alternatives** If you prefer not to use a library like Lodash or want to explore alternative approaches, you could consider: 1. Using `forEach` instead of `_map` or `array.map`. 2. Implementing your own custom iterator using `for...of` loops. 3. Utilizing Web Workers for parallel processing. However, keep in mind that these alternatives might not be as efficient or straightforward to implement as the tested methods.
Related benchmarks:
Array.prototype.map vs Lodash.map
Array.prototype.map vs Lodash map
Array.prototype.map vs Lodash.map on large data
array.map vs _.map
native map vs lodash map on large array
Comments
Confirm delete:
Do you really want to delete benchmark?