<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.js"></script>
var data = [1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,];
data.map(function (number) { return number * 2});
_.map(data, function (number) { return number * 2});
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Array.prototype.map | |
Lodash.map |
Test name | Executions per second |
---|---|
Array.prototype.map | 7412017.0 Ops/sec |
Lodash.map | 14126708.0 Ops/sec |
Let's break down the provided JSON and explain what's being tested.
Benchmark Definition
The benchmark is testing the performance of two approaches to transform an array: Array.prototype.map
( native JavaScript function) and Lodash.map
(a library function).
Options Compared
The two options being compared are:
Array.prototype.map
_.map
Both functions take an array as input, iterate over its elements, apply a transformation to each element, and return a new array with the transformed elements.
Pros and Cons of Each Approach
Array.prototype.map
):_.map
):Library Used: Lodash
Lodash is a popular JavaScript utility library that provides a collection of functional programming helpers, including _.map
. It's designed to make common tasks easier by providing pre-built functions for things like array manipulation, string manipulation, and object manipulation.
The version used in this benchmark is 4.17.15.
Special JS Feature/Syntax: None
There are no special JavaScript features or syntaxes being tested in this benchmark.
Other Alternatives
If you want to test alternative approaches for transforming arrays, you could consider:
function
declaration, you could use an arrow function (() => { code }
) to define the transformation function.Keep in mind that these alternatives might not be directly comparable to Array.prototype.map
or Lodash.map
, as they often introduce additional complexity or overhead.