var N = 1000000;
var x = new Float32Array(N);
var y = new Float32Array(N);
var z = new Float32Array(N);
var interlaced = new Float32Array(3*N);
var vectors = [];
for (var i = 0, li=x.length; i < li; ++i) {
x[i] = Math.random();
y[i] = Math.random();
z[i] = Math.random();
vectors.push( {x: Math.random(), y: Math.random(), z: Math.random()} );
}
for (var i = 0, li=interlaced.length; i < li; ++i) {
interlaced[i] = Math.random();
}
var vector;
for (var i = 0, li=vectors.length; i < li; ++i) {
vector = vectors[i];
vector.x = 2 * vector.x;
vector.y = 2 * vector.y;
vector.z = 2 * vector.z;
}
for (var i = 0, li=x.length; i < li; ++i) {
x[i] = 2 * x[i];
y[i] = 2 * y[i];
z[i] = 2 * z[i];
}
for (var i = 0, li=interlaced.length; i < li; ++i) {
interlaced[i] = 2*interlaced[i];
}
for (var i = 0, li=interlaced.length; i < li; i+=3) {
interlaced[i] = 2*interlaced[i];
interlaced[i+1] = 2*interlaced[i+1];
interlaced[i+2] = 2*interlaced[i+2];
}
for (var i = 0, li=x.length; i < li; ++i) {
x[i] = 2 * x[i];
}
for (var i = 0, li=y.length; i < li; ++i) {
y[i] = 2 * y[i];
}
for (var i = 0, li=z.length; i < li; ++i) {
z[i] = 2 * z[i];
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
AoS | |
SoA | |
Interlaced Array - no loop unrolling | |
Interlaced Array - with loop unrolling | |
SoA - one component per loop |
Test name | Executions per second |
---|---|
AoS | 1.3 Ops/sec |
SoA | 1.8 Ops/sec |
Interlaced Array - no loop unrolling | 1.8 Ops/sec |
Interlaced Array - with loop unrolling | 1.6 Ops/sec |
SoA - one component per loop | 0.7 Ops/sec |
Let's break down what's being tested in the provided benchmark.
Benchmark Definition
The benchmark is designed to compare three approaches for multiplying lists of vectors:
Options Compared
Each test case compares two approaches: one with loop unrolling and one without.
Pros and Cons
Library Used
None explicitly mentioned in the benchmark definition. However, the use of Float32Array
suggests that JavaScript's built-in array support is being used to store numerical data.
Special JS Features or Syntax
No special features or syntax are used in this benchmark. The code follows standard JavaScript syntax and semantics.
Execution Results
The execution results show that:
These results suggest that SoA with loop unrolling is a good choice for this specific benchmark. However, it's essential to note that performance may vary depending on the specific use case and requirements.