const list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for (let i = 0; i < list.length; i++) {
var sum = i + 1;
}
const list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for (let i = 0; i < list.length; i++) {
var sum = i + 1;
console.log(sum);
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Without console | |
With console |
Test name | Executions per second |
---|---|
Without console | 157071312.0 Ops/sec |
With console | 18320.2 Ops/sec |
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net.
What is being tested?
The provided benchmark tests the performance impact of logging output to the console using console.log()
in two different scenarios:
console.log()
: This test case creates a list of numbers and iterates over it, calculating the sum of each element. The console.log()
function is not used.console.log()
: This test case is similar to the first one, but with the addition of logging the calculated sum using console.log()
.Options compared
The two test cases compare the performance difference between running JavaScript code without logging output and with logging output. In other words:
Pros and Cons
Library and syntax
There are no external libraries used in these test cases. However, JavaScript's built-in console
object is being tested.
No special JavaScript features or syntax are being tested in this benchmark.
Other alternatives
If you're interested in exploring alternative approaches, here are a few examples:
Keep in mind that MeasureThat.net is specifically designed to test the performance impact of logging output, so these alternatives may not be directly applicable to this specific use case.