Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
matrix test
(version: 0)
test patterns for matrix perf
Comparing performance of:
vec3 Arr vs vec3 obj vs vec3 arr2
Created:
9 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function addObj(out, a, b) { out[0] = a[0] + b[0]; out[1] = a[1] + b[1]; out[2] = a[2] + b[2]; return out; }; function addArr(out, oo, a, b, ao,bo) { out[0+oo] = a[0+ao] + b[0+bo]; out[1+oo] = a[1+ao] + b[1+bo]; out[2+oo] = a[2+ao] + b[2+bo]; }; function addArr2(out, a, b, oo, ao,bo) { out[0+(oo || 0)] = a[0+(ao || 0)] + b[0+(bo || 0)]; out[1+(oo || 0)] = a[1+(ao || 0)] + b[1+(bo || 0)]; out[2+ (oo || 0)] = a[2+(ao || 0)] + b[2+(bo || 0)]; };
Tests:
vec3 Arr
var A = new Float32Array(300); var B = new Float32Array(300); var O = new Float32Array(300); for (var i = 0;i < 10000;++i) { for (var j=0;j< 100;++j) { addArr(O,j*3,A,B,j*3,j*3); } }
vec3 obj
var A = []; var B = []; var O = []; for (var x=0;x<100;++x) { A.push(new Float32Array(3)); B.push(new Float32Array(3)); O.push(new Float32Array(3)); } for (var i = 0;i < 10000;++i) { for (var j=0;j< 100;++j) { addObj(O[j],A[j],B[j]); } }
vec3 arr2
var A = new Float32Array(300); var B = new Float32Array(300); var O = new Float32Array(300); for (var i = 0;i < 10000;++i) { for (var j=0;j< 100;++j) { addArr2(O,A,B,j * 3,j*3,j*3); } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
vec3 Arr
vec3 obj
vec3 arr2
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Definition JSON** The provided JSON represents a benchmark definition, which is a set of instructions that outline how to create and execute the benchmark. In this case, we have three test cases: `vec3 Arr`, `vec3 obj`, and `vec3 arr2`. Each test case has its own script preparation code, which defines functions for adding elements to arrays (`addObj` and `addArr`) or using a default function for adding elements (`addArr2`). **Options Compared** The three test cases compare different approaches for adding elements to arrays: 1. `vec3 Arr`: Uses the `push` method to add new arrays to an array, followed by calling `addObj` on each element. 2. `vec3 obj`: Creates a new array with initial values using `new Float32Array(3)`, and then pushes this array into another array. Finally, it calls `addObj` on each element of the nested array. 3. `vec3 arr2`: Uses the default function for adding elements to arrays (`addArr2`) to add elements directly to an existing array. **Pros and Cons** * **Push method (vec3 Arr)**: + Pros: Efficient use of memory, as no new arrays need to be created. + Cons: May incur overhead due to frequent calls to `push`. * **Array creation with initial values (vec3 obj)**: + Pros: Can take advantage of browser optimizations for creating arrays with initial values. + Cons: Requires more memory allocation and may incur performance overhead due to the creation of intermediate arrays. * **Default function for adding elements (vec3 arr2)**: + Pros: Eliminates the need for explicit array additions, which can be faster and more efficient. + Cons: May not work as expected if the default function is not optimized or does not handle edge cases correctly. **Other Considerations** * **Array performance**: JavaScript arrays are a fundamental data structure in modern web applications. Understanding how to optimize array operations is crucial for achieving good performance. * **Browser variations**: MeasureThat.net tests different browsers, which can affect the results due to varying implementations and optimizations. **Library Used** None of the test cases explicitly use any external libraries beyond the built-in `Float32Array` type. **Special JS Features or Syntax** None of the test cases rely on special JavaScript features or syntax beyond the standard language specification.
Related benchmarks:
=== vs .includes
2dArray[a][b] vs getValue(obj, a, b);
Array find middle
Check better performance
test array and set
Comments
Confirm delete:
Do you really want to delete benchmark?