<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>
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() {
return underscore.map(PromosArray, function (promo) {
return promo.type;
});
}
function testLodashMap() {
return lodash.map(PromosArray, function (promo) {
return promo.type;
});
}
testArrayIteration();
testArrayMap();
testUnderscoreMap();
testLodashMap();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
testArrayIteration | |
testArrayMap | |
testUnderscoreMap | |
testLodashMap |
Test name | Executions per second |
---|---|
testArrayIteration | 37725312.0 Ops/sec |
testArrayMap | 11395883.0 Ops/sec |
testUnderscoreMap | 12907391.0 Ops/sec |
testLodashMap | 14704527.0 Ops/sec |
Let's dive into the benchmark.
What is being tested?
The provided JSON represents a JavaScript microbenchmark that tests the performance of different methods for iterating over an array in JavaScript. Specifically, it compares four approaches:
for
loop to iterate over each element in the array.map()
method to create a new array with the results of applying a provided function to each element in the original array.map()
function: A utility function from the Lodash library that provides a more concise way to iterate over an array and transform its elements.map()
function: Another utility function from the Underscore.js library that offers a similar functionality to Lodash's map()
.Options compared
The benchmark compares these four approaches in terms of their performance, specifically the number of executions per second (measured in "ExecutionsPerSecond").
Pros and cons of each approach
map()
function:map()
.map()
function:map()
as mentioned above.Special JS feature or syntax
None mentioned in the benchmark.
Other considerations
The benchmark is likely designed to provide insights into the performance characteristics of different JavaScript iteration methods. By comparing these approaches, developers can make informed decisions about which method to use depending on their specific use case and requirements.
If you're interested in running this benchmark yourself, you'll need to:
Alternatives
If you're looking for alternative benchmarking libraries, some popular options include:
These alternatives may offer more features, flexibility, or accuracy than MeasureThat.net, but they often require more setup and expertise to use effectively.