Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Underscore map vs Array map
(version: 0)
Underscore map vs Array map
Comparing performance of:
Underscore map vs Array map
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js'></script>
Script Preparation code:
var primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,97]
Tests:
Underscore map
var result = _.map(primes,(prime) => {return prime});
Array map
var result = primes.map((prime) => {return prime});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Underscore map
Array map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Underscore map
16396075.0 Ops/sec
Array map
17599966.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases. **Benchmark Definition:** The benchmark compares two approaches to perform mapping operations on an array of numbers (primes): using the `_.map()` function from the Underscore.js library, and using the native `Array.prototype.map()` method in JavaScript. **Script Preparation Code:** The script preparation code defines an array of prime numbers (`primes`). ```javascript var primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,97]; ``` **HTML Preparation Code:** The HTML preparation code includes a reference to the Underscore.js library. ```html <script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js'></script> ``` **Individual Test Cases:** 1. **Underscore map:** The first test case uses the `_.map()` function from Underscore.js to perform mapping operations on the `primes` array. ```javascript var result = _.map(primes,(prime) => {return prime}); ``` This approach relies on the Underscore.js library, which provides a convenient way to perform common functional programming tasks. 2. **Array map:** The second test case uses the native `Array.prototype.map()` method in JavaScript to perform mapping operations on the `primes` array. ```javascript var result = primes.map((prime) => {return prime}); ``` This approach is a built-in part of JavaScript and does not rely on any external libraries. **Options Compared:** * The two options being compared are: + Using the Underscore.js library (`_.map()`) vs. + Using the native `Array.prototype.map()` method in JavaScript. * These two approaches have different performance characteristics due to various factors, such as: + Overhead of function calls and variable lookups with Underscore.js + Optimizations implemented by the JavaScript engine for native methods **Pros and Cons:** * **Underscore.js (`_.map()`):** Pros: - Simplifies functional programming tasks - Can provide a more consistent and predictable API - May offer better performance in certain scenarios due to caching and memoization - Reduces the need for manual loop-based iteration Cons: - Requires an additional external library, which can introduce latency and overhead - May not be optimized for specific use cases or workloads * **Native `Array.prototype.map()`:** Pros: - Built-in to JavaScript, reducing the need for external libraries - Can offer better performance in many scenarios due to engine optimizations - Simplifies code by eliminating the need for explicit loop-based iteration Cons: - May not provide a consistent API across all browsers or environments - Can result in slower performance in certain edge cases due to overhead of function calls and variable lookups **Library:** Underscore.js is a popular JavaScript library that provides a set of functional programming helpers, including `_.map()`. It's designed to simplify common tasks and provide a consistent API. **Special JS Feature or Syntax:** This benchmark does not rely on any special features or syntax specific to modern JavaScript versions. Both test cases use standard JavaScript syntax and features. **Alternatives:** * For building more complex data processing pipelines, you may consider using other libraries like Lodash or Ramda. * If performance is a critical concern, you might explore optimizing the native `Array.prototype.map()` method or leveraging specialized libraries for high-performance data processing.
Related benchmarks:
Underscore vs Array functions
Underscore filter vs Array filter
Underscore each vs while
test js includes and some
Comments
Confirm delete:
Do you really want to delete benchmark?