Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
soa vs aos
(version: 0)
As titled
Comparing performance of:
soa vs aos vs soa mark II
Created:
9 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var N = 1000000; var x = [], y = [], z = []; var xt = new Float32Array(1000000); var yt = new Float32Array(1000000); var zt = new Float32Array(1000000); var vectors = []; for(var i = 0; i < N; i++){ x[i] = Math.random(); y[i] = Math.random(); z[i] = Math.random(); xt[i] = x[i]; yt[i] = y[i]; zt[i] = z[i]; vectors[i] = { x: x[i], y: y[i], z: z[i] }; } var vector;
Tests:
soa
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]; }
aos
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; }
soa mark II
for (var i = 0, li=x.length; i < li; ++i) { xt[i] = 2 * xt[i]; } for (var i = 0, li=x.length; i < li; ++i) { yt[i] = 2 * yt[i]; } for (var i = 0, li=x.length; i < li; ++i) { zt[i] = 2 * zt[i]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
soa
aos
soa mark II
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:139.0) Gecko/20100101 Firefox/139.0
Browser/OS:
Firefox 139 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
soa
88.3 Ops/sec
aos
123.1 Ops/sec
soa mark II
290.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the benchmark analysis. **Benchmark Definition** The benchmark is comparing two approaches to scaling out a loop: **Single-Assignment Optimization (SOA)** and **Arrays of Structures (AoS)**. In SOA, each iteration modifies a single variable that is assigned a new value in the next iteration. In AoS, each iteration works on an entire structure (in this case, an object with three properties) and assigns it to a temporary variable. **Benchmark Preparation Code** The preparation code creates four arrays: `x`, `y`, `z` (with 1 million elements each), and `xt`, `yt`, `zt` (also with 1 million elements each). It then populates these arrays with random values and copies the values from `x`, `y`, and `z` to `xt`, `yt`, and `zt`. Finally, it creates an array of objects (`vectors`) with three properties: `x`, `y`, and `z`. **Individual Test Cases** There are three test cases: 1. **SOA**: The loop iterates over the length of `x` (or `y`, or `z`) and modifies each element directly. 2. **AoS**: The loop iterates over the length of `vectors` and works on an entire object (`vector`). It copies the modified value back to the original array (`xt`, `yt`, or `zt`). 3. **SOA Mark II**: A variation of SOA that applies only to the `xt`, `yt`, and `zt` arrays, while leaving the `x`, `y`, and `z` arrays unchanged. **Options Compared** * SOA (Single-Assignment Optimization): Modifies each element directly in place. * AoS (Arrays of Structures): Works on an entire structure (object) and assigns it to a temporary variable. **Pros and Cons** * **SOA**: + Pros: Typically faster since it avoids copying values. + Cons: Can lead to performance issues if the array size is large, as modifying each element individually can be slower than working on a larger data structure. * **AoS**: + Pros: Easier to implement and maintain, as it separates concerns between iteration and modification. + Cons: May incur overhead from copying values. **Library Used** In this benchmark, there is no explicit library used. However, the use of `Float32Array` suggests that the benchmark targets modern JavaScript environments with optimized array support. **Special JS Features/Syntax** This benchmark does not explicitly use any special JavaScript features or syntax. **Other Alternatives** If you wanted to create a similar benchmark, you could consider alternative approaches, such as: * **AoS with Caching**: Implementing caching for frequently accessed values in the `vectors` array. * **SOA with Loop Unrolling**: Optimizing the loop iteration count and using unrolling techniques to reduce overhead. Keep in mind that these alternatives would require significant changes to the benchmark preparation code.
Related benchmarks:
soa vs aos
soa vs aos
soa vs aos
soa vs aos
Comments
Confirm delete:
Do you really want to delete benchmark?