<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
var max1 = 100000; // 100,000 (100 Thousand)
var max2 = 10000000; // 10,000,000 (10 Million)
var max3 = 100000000; // 100,000,000 (100 Million)
var arr1 = [];
//for (var i = 0; i <= max1; i++) { arr1.push(i); }
var arr2 = [];
for (var i = 0; i <= max2; i++) { arr2.push(i); }
var arr3 = [];
//for (var i = 0; i <= max3; i++) { arr3.push(i); }
var array2 = arr2.map(function (value, index) {
return value * 2
})
var array2 = _.map(arr2, function (value, index) {
return value * 2
})
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Native | |
lodash |
Test name | Executions per second |
---|---|
Native | 0.4 Ops/sec |
lodash | 3.2 Ops/sec |
Let's break down the provided benchmark definition and test cases to understand what's being tested.
Benchmark Definition
The benchmark is comparing two approaches:
map
function of JavaScript arrays, which is native to the language._.map
function from the Lodash library, a popular utility library for JavaScript.Options being compared
Pros and Cons
Native (Built-in map
function)
Pros:
Cons:
Lodash.js map
Pros:
map
function.Cons:
Library used: Lodash.js
Lodash.js is a popular JavaScript utility library that provides a comprehensive set of functions for common tasks such as array manipulation, string manipulation, and more. The _.map
function is part of this library and allows for concise and expressive data transformation.
Special JS feature or syntax
There isn't any specific JavaScript feature or syntax being tested in these benchmarks. The focus is on comparing the performance of native map
function versus Lodash.js map.
Other alternatives
If you're looking for alternative libraries to Lodash.js, some popular options include:
Keep in mind that the choice of library depends on your specific use case, performance requirements, and personal preference.