var arr = [];
for (var x = 0; x < 10000; x++)
{
arr[x]=[];
}
for (var i=0; i < 10000; i++)
{
for (var j=0; j < 10000; j++)
{
arr[i][j]=i*j;
}
}
for (var i=0; i < 10000; i++)
{
for (var j=0; j < 10000; j++)
{
arr[j][i]=i*j;
}
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
IJ | |
JI |
Test name | Executions per second |
---|---|
IJ | 0.1 Ops/sec |
JI | 0.1 Ops/sec |
I'd be happy to explain what's being tested in this benchmark.
Benchmark Overview
The benchmark compares the performance of two approaches: nested loops with i
as the outer loop and j
as the inner loop, versus nested loops with j
as the outer loop and i
as the inner loop. The loop iterates 10,000 times in each direction.
Script Preparation Code
The script preparation code initializes an empty array arr
and populates it with another empty array for each iteration of the outer loop (x
). This is done to ensure that the inner loops have access to the correct index values.
Options Compared
There are two main options being compared:
i
as Outer Loop and j
as Inner Loopfor (var i=0; i < 10000; i++) { for (var j=0; j < 10000; j++) { arr[i][j]=i*j; } }
j
as Outer Loop and i
as Inner Loopfor (var i=0; i < 10000; i++) { for (var j=0; j < 10000; j++) { arr[j][i]=i*j; } }
arr
with each inner loop iteration, which can lead to additional memory access and calculations.Pros and Cons
i
as Outer Loop:j
as Outer Loop:Other Considerations
i*j
or j*i
. This can add unnecessary complexity and overhead.Library Usage
There is no explicit library usage in the benchmark definition. However, the use of JavaScript's built-in for
loops and array indexing suggests that the browser's V8 engine (used by Chrome 52) provides the necessary functionality for array manipulation and iteration.
Special JS Features/Syntax
There are no special JavaScript features or syntax used in this benchmark beyond standard loop constructs and array indexing.