<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() {
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;
}
}
testArrayIteration();
testArrayMap();
testUnderscoreMap();
testLodashMap();
testForLoop();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
testArrayIteration | |
testArrayMap | |
testUnderscoreMap | |
testLodashMap | |
testForLoop |
Test name | Executions per second |
---|---|
testArrayIteration | 9268117.0 Ops/sec |
testArrayMap | 6085396.5 Ops/sec |
testUnderscoreMap | 2445886.2 Ops/sec |
testLodashMap | 4222851.5 Ops/sec |
testForLoop | 22455824.0 Ops/sec |
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:
map()
map()
map()
Each approach is compared with the others, and the results are displayed in a chart.
Options Compared
The four options being compared are:
map()
: The map()
method is called on the array to create a new array with the desired output.map()
: Underscore.js, a popular utility library, provides its own implementation of the map()
method.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:
map()
map()
map()
Library Overview
The benchmark uses two utility libraries:
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:
I hope this explanation helps you understand what's being tested in this benchmark!