Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Promo Map
(version: 0)
Comparing performance of:
testArrayIteration vs testArrayMap vs testUnderscoreMap vs testLodashMap vs testForLoop
Created:
9 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script> <script> underscore = _; </script> <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.12.0/lodash.min.js"></script> <script> lodash = _; </script> </head> <body> </body> </html>
Script Preparation code:
var PromosArray = [ { type: "regular", display: "$123.00" }, { type: "markdown", display: "$100.00" }, { type: "promo", display: "$80.00" } ]; function testArrayIteration() { var items = []; var i; for (i = 0; i < PromosArray.length; i++) { items.push(PromosArray[i].type); } return items; } function testArrayMap() { return PromosArray.map(function (promo) { return promo.type; }); } function testUnderscoreMap() { underscore.map(PromosArray, function (promo) { return promo.type; }); } function testLodashMap() { lodash.map(PromosArray, function (promo) { return promo.type; }); } function testForLoop() { for (var i = 0; i < PromosArray.length; i++) { return PromosArray[i].type; } }
Tests:
testArrayIteration
testArrayIteration();
testArrayMap
testArrayMap();
testUnderscoreMap
testUnderscoreMap();
testLodashMap
testLodashMap();
testForLoop
testForLoop();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
testArrayIteration
testArrayMap
testUnderscoreMap
testLodashMap
testForLoop
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 MeasureThat.net and explore what's being tested in this benchmark. **Benchmark Overview** The benchmark is designed to compare the performance of four different approaches for iterating over an array: 1. **For Loop** 2. **Array Iteration using `map()`** 3. **Underscore.js `map()`** 4. **Lodash.js `map()`** Each approach is compared with the others, and the results are displayed in a chart. **Options Compared** The four options being compared are: 1. **For Loop**: A traditional for loop that iterates over the array elements. 2. **Array Iteration using `map()`**: The `map()` method is called on the array to create a new array with the desired output. 3. **Underscore.js `map()`**: Underscore.js, a popular utility library, provides its own implementation of the `map()` method. 4. **Lodash.js `map()`**: Lodash.js, another utility library, also provides an implementation of the `map()` method. **Pros and Cons** Here are some pros and cons for each approach: 1. **For Loop** * Pros: Simple, intuitive, and widely supported. * Cons: Can be slower than other approaches due to the overhead of the loop control logic. 2. **Array Iteration using `map()`** * Pros: Concise, expressive, and can be faster than traditional for loops. * Cons: May incur additional overhead due to the creation of a new array. 3. **Underscore.js `map()`** * Pros: Provides a consistent and predictable behavior across different browsers. * Cons: Adds an extra dependency on Underscore.js library, which may not be necessary for all use cases. 4. **Lodash.js `map()` * Pros: Similar to Underscore.js, providing a consistent behavior, but with additional functionality. * Cons: Also adds an extra dependency on Lodash.js library. **Library Overview** The benchmark uses two utility libraries: 1. **Underscore.js**: A lightweight functional programming library that provides a set of utility functions for working with arrays and other data structures. 2. **Lodash.js**: A more comprehensive utility library that builds upon Underscore.js, providing additional functionality such as array methods, string manipulation, and more. **Special JS Feature/Syntax** None of the test cases use special JavaScript features or syntax beyond standard ES5/ES6 programming. The benchmark is designed to be language-agnostic, making it applicable to a wide range of browsers and environments. **Other Alternatives** If you're looking for alternatives to MeasureThat.net, here are some options: 1. **Benchmark.js**: A popular benchmarking library that allows you to write custom benchmarks using JavaScript. 2. **Benchmark Suite**: A collection of benchmarks written in JavaScript, covering various topics such as DOM manipulation, event handling, and more. 3. **jsperf**: An older benchmarking tool that allowed users to compare the performance of different JavaScript implementations. I hope this explanation helps you understand what's being tested in this benchmark!
Related benchmarks:
Array.prototype.map vs Lodash.map
Array.prototype.map vs Lodash.map 4.17.15
lodash vs es6 in map method
array.map vs _.map
Test map
Comments
Confirm delete:
Do you really want to delete benchmark?