<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
const tabs = [100, 200, 300, 400, 500];
console.log( _.sum(tabs) );
const tabs = [100, 200, 300, 400, 500];
console.log( tabs.reduce((a,b) => a+b) );
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
lodash sum | |
javascript reduce |
Test name | Executions per second |
---|---|
lodash sum | 284296.8 Ops/sec |
javascript reduce | 287276.9 Ops/sec |
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net.
Benchmark Overview
MeasureThat.net provides a platform for comparing the performance of different JavaScript approaches to solve the same problem. The provided JSON represents two benchmark definitions:
sum
function versus a simple addition loop.reduce
method.Benchmark Options Compared
In both cases, we have two options to compare:
reduce
method provided by JavaScript.reduce
.Pros and Cons of Each Approach
Library: Lodash
Lodash is a popular JavaScript utility library that provides various functions to simplify tasks, such as array manipulation, functional programming, and more. In this benchmark, we use the sum
function from Lodash to perform the summation. Other useful functions in Lodash include pipe
, map
, filter
, and many others.
Special JS Feature/Syntax
In this benchmark, there is no specific JavaScript feature or syntax used that would be unique or noteworthy. Both tests rely on standard JavaScript concepts, such as loops, array manipulation, and the use of libraries like Lodash.
Other Alternatives
If you're looking for alternatives to MeasureThat.net, here are a few options:
I hope this explanation helps you understand the basics of MeasureThat.net and its usage!