Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Mat3 Multiplication
(version: 0)
Comparing performance of:
Store values in consts first vs Store values in consts first (arranged) vs Access values directly
Created:
7 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
class Mat3_Consts extends Float32Array { constructor() { super(9); this[0] = Math.random(); this[1] = Math.random(); this[2] = Math.random(); this[3] = Math.random(); this[4] = Math.random(); this[5] = Math.random(); this[6] = Math.random(); this[7] = Math.random(); this[8] = Math.random(); } mul(that) { const x1 = this[0]; const x2 = this[1]; const x3 = this[2]; const y1 = this[3]; const y2 = this[4]; const y3 = this[5]; const z1 = this[6]; const z2 = this[7]; const z3 = this[8]; const a1 = that[0]; const a2 = that[1]; const a3 = that[2]; const b1 = that[3]; const b2 = that[4]; const b3 = that[5]; const c1 = that[6]; const c2 = that[7]; const c3 = that[8]; this[0] = x1 * a1 + x2 * b1 + x3 * c1; this[1] = x1 * a2 + x2 * b2 + x3 * c2; this[2] = x1 * a3 + x2 * b3 + x3 * c3; this[3] = y1 * a1 + y2 * b1 + y3 * c1; this[4] = y1 * a2 + y2 * b2 + y3 * c2; this[5] = y1 * a3 + y2 * b3 + y3 * c3; this[6] = z1 * a1 + z2 * b1 + z3 * c1; this[7] = z1 * a2 + z2 * b2 + z3 * c2; this[8] = z1 * a3 + z2 * b3 + z3 * c3; return this; } } class Mat3_ConstsArranged extends Float32Array { constructor() { super(9); this[0] = Math.random(); this[1] = Math.random(); this[2] = Math.random(); this[3] = Math.random(); this[4] = Math.random(); this[5] = Math.random(); this[6] = Math.random(); this[7] = Math.random(); this[8] = Math.random(); } mul(that) { const x1 = this[0]; const a1 = that[0]; const x2 = this[1]; const b1 = that[3]; const x3 = this[2]; const c1 = that[6]; const y1 = this[3]; const a2 = that[1]; const y2 = this[4]; const b2 = that[4]; const y3 = this[5]; const c2 = that[7]; const z1 = this[6]; const a3 = that[2]; const z2 = this[7]; const b3 = that[5]; const z3 = this[8]; const c3 = that[8]; this[0] = x1 * a1 + x2 * b1 + x3 * c1; this[1] = x1 * a2 + x2 * b2 + x3 * c2; this[2] = x1 * a3 + x2 * b3 + x3 * c3; this[3] = y1 * a1 + y2 * b1 + y3 * c1; this[4] = y1 * a2 + y2 * b2 + y3 * c2; this[5] = y1 * a3 + y2 * b3 + y3 * c3; this[6] = z1 * a1 + z2 * b1 + z3 * c1; this[7] = z1 * a2 + z2 * b2 + z3 * c2; this[8] = z1 * a3 + z2 * b3 + z3 * c3; return this; } } class Mat3_Accesses extends Float32Array { constructor() { super(9); this[0] = Math.random(); this[1] = Math.random(); this[2] = Math.random(); this[3] = Math.random(); this[4] = Math.random(); this[5] = Math.random(); this[6] = Math.random(); this[7] = Math.random(); this[8] = Math.random(); } mul(that) { this[0] = this[0] * that[0] + this[1] * that[3] + this[2] * that[6]; this[1] = this[0] * that[1] + this[1] * that[4] + this[2] * that[7]; this[2] = this[0] * that[2] + this[1] * that[5] + this[2] * that[8]; this[3] = this[3] * that[0] + this[4] * that[3] + this[5] * that[6]; this[4] = this[3] * that[1] + this[4] * that[4] + this[5] * that[7]; this[5] = this[3] * that[2] + this[4] * that[5] + this[5] * that[8]; this[6] = this[6] * that[0] + this[7] * that[3] + this[8] * that[6]; this[7] = this[6] * that[1] + this[7] * that[4] + this[8] * that[7]; this[8] = this[6] * that[2] + this[7] * that[5] + this[8] * that[8]; return this; } } var MatA1 = new Mat3_Consts(); var MatA2 = new Mat3_Consts(); var MatB1 = new Mat3_ConstsArranged(); var MatB2 = new Mat3_ConstsArranged(); var MatC1 = new Mat3_Accesses(); var MatC2 = new Mat3_Accesses();
Tests:
Store values in consts first
MatA1.mul(MatA2);
Store values in consts first (arranged)
MatB1.mul(MatB2);
Access values directly
MatC1.mul(MatC2)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Store values in consts first
Store values in consts first (arranged)
Access values directly
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):
A complex benchmarking report! To provide an answer, I'll need to analyze the provided code and test cases. **Code Analysis** The code is written in JavaScript and defines three classes: `Mat3_Consts`, `Mat3_ConstsArranged`, and `Mat3_Accesses`. Each class has a constructor and a `mul` method. The `mul` method multiplies two matrices, `MatA1` and `MatB1`, or `MatB2`, respectively. The code also defines four test cases: * `Store values in consts first`: This test case compares the execution time of multiplying two matrices using the `Mat3_Consts` class versus the `Mat3_ConstsArranged` class. * `Store values in consts first (arranged)`: Similar to the previous test case, but with a different arrangement of constants. * `Access values directly`: This test case compares the execution time of multiplying two matrices using the `Mat3_Accesses` class versus the `Mat3_Consts` class. **Benchmarking Results** The benchmarking results are provided in the "Latest benchmark result" section. The results show the number of executions per second for each test case: * `Store values in consts first`: 482,638,008.0 * `Store values in consts first (arranged)`: 459,114,112.0 * `Access values directly`: 274,113,048.0 **Answer** Based on the benchmarking results, it appears that: 1. Using `Mat3_Consts` class provides a significant performance improvement over using `Mat3_ConstsArranged` or accessing constants directly (`Mat3_Accesses`). The first approach is approximately 5-7 times faster. 2. There is no significant difference in execution time between the two matrix multiplication approaches using `Mat3_ConstsArranged` and `Mat3_Accesses`. Therefore, for optimal performance, it is recommended to use the `Mat3_Consts` class when multiplying matrices.
Related benchmarks:
Random I/O various arrays
concat.apply short form new array vs flat
Comparing array.concat.apply short form with empty array vs array.flat vs array.reduce
set vs subarray-set vs pre-allocated subarray-set
Array item swapping, destructuring vs temp variable vs xor
Comments
Confirm delete:
Do you really want to delete benchmark?