@@ -22,26 +22,37 @@ class LinearAlgebraWorkloadBenchmark extends BLASBenchmark:
2222 var dataB : Array [Double ] = uninitialized
2323 var vectorData : Array [Double ] = uninitialized
2424
25- @ Setup (Level .Invocation )
25+ // Pre-created matrices for pure computation benchmarking
26+ var breezeMatA : DenseMatrix [Double ] = uninitialized
27+ var breezeMatB : DenseMatrix [Double ] = uninitialized
28+ var breezeVec : DenseVector [Double ] = uninitialized
29+
30+ var vecxtMatA : vecxt.matrix.Matrix [Double ] = uninitialized
31+ var vecxtMatB : vecxt.matrix.Matrix [Double ] = uninitialized
32+
33+ @ Setup (Level .Trial ) // Only once per iteration
2634 def setup (): Unit =
2735 val dim = matDim.toInt
2836 dataA = randomDoubleArray(dim * dim)
2937 dataB = randomDoubleArray(dim * dim)
3038 vectorData = randomDoubleArray(dim)
39+
40+ // Pre-create matrices to exclude construction overhead
41+ breezeMatA = new DenseMatrix (dim, dim, dataA.clone())
42+ breezeMatB = new DenseMatrix (dim, dim, dataB.clone())
43+ breezeVec = new DenseVector (vectorData.clone())
44+
45+ vecxtMatA = vecxt.matrix.Matrix (dataA.clone(), (dim, dim))
46+ vecxtMatB = vecxt.matrix.Matrix (dataB.clone(), (dim, dim))
3147 end setup
3248
3349 @ Benchmark
3450 def breezeWorkload (bh : Blackhole ): Unit =
35- val dim = matDim.toInt
36- // Create matrices and vector from the same data
37- val matA = new DenseMatrix (dim, dim, dataA)
38- val matB = new DenseMatrix (dim, dim, dataB)
39- val vec = new DenseVector (vectorData)
4051
4152 // Representative linear algebra workload
42- val step1 = matA + matB // Element-wise addition
43- val step2 = step1 *:* matA // Hadamard product
44- val step3 = step2 * vec // Matrix-vector multiply
53+ val step1 = breezeMatA + breezeMatB // Element-wise addition
54+ val step2 = step1 *:* breezeMatA // Hadamard product
55+ val step3 = step2 * breezeVec // Matrix-vector multiply
4556 val step4 = step3.map(_ * 2.0 + 1.0 ) // Element-wise transform
4657 val step5 = breeze.linalg.norm(step4) // L2 norm
4758 // val step6 = step2.t // Transpose
@@ -55,14 +66,10 @@ class LinearAlgebraWorkloadBenchmark extends BLASBenchmark:
5566
5667 @ Benchmark
5768 def vecxtWorkload (bh : Blackhole ): Unit =
58- val dim = matDim.toInt
59- // Create matrices and vector from the same data
60- val matA = vecxt.matrix.Matrix (dataA, (dim, dim))
61- val matB = vecxt.matrix.Matrix (dataB, (dim, dim))
6269
6370 // Same representative linear algebra workload
64- val step1 = matA + matB // Element-wise addition
65- val step2 = step1.hadamard(matA ) // Hadamard product
71+ val step1 = vecxtMatA + vecxtMatB // Element-wise addition
72+ val step2 = step1.hadamard(vecxtMatA ) // Hadamard product
6673 val step3 = step2 * vectorData // Matrix-vector multiply
6774 val step4 = step3.fma(2.0 , 1.0 ) // Element-wise transform
6875 val step5 = step4.norm // L2 norm
0 commit comments