|
| 1 | +package bench |
| 2 | + |
| 3 | +import ( |
| 4 | + "algo/math" |
| 5 | + "testhelper" |
| 6 | + "testing" |
| 7 | +) |
| 8 | + |
| 9 | +const test_size = 500 |
| 10 | + |
| 11 | +/* |
| 12 | + Test result when ma and mb are both 5000 x 5000 matrix |
| 13 | + goos: windows |
| 14 | + goarch: amd64 |
| 15 | + BenchmarkMatMulSlow-8 1 2114916672000 ns/op |
| 16 | + BenchmarkMatMulTiling16-8 1 362979711200 ns/op |
| 17 | + BenchmarkMatMulTiling24-8 1 373598301500 ns/op |
| 18 | + BenchmarkMatMulTiling32-8 1 376010471000 ns/op |
| 19 | +*/ |
| 20 | + |
| 21 | +func BenchmarkMatMulSlow(b *testing.B) { |
| 22 | + ma := testhelper.GenMat(test_size, test_size, 1) |
| 23 | + mb := testhelper.GenMat(test_size, test_size, 2) |
| 24 | + b.ResetTimer() |
| 25 | + for i := 0; i < b.N; i++ { |
| 26 | + math.MatmulSlow(ma, mb) |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +func BenchmarkMatMulTiling16(b *testing.B) { |
| 31 | + ma := testhelper.GenMat(test_size, test_size, 1) |
| 32 | + mb := testhelper.GenMat(test_size, test_size, 2) |
| 33 | + b.ResetTimer() |
| 34 | + for i := 0; i < b.N; i++ { |
| 35 | + math.MatmulTiling(ma, mb, 16) |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +func BenchmarkMatMulTiling24(b *testing.B) { |
| 40 | + ma := testhelper.GenMat(test_size, test_size, 1) |
| 41 | + mb := testhelper.GenMat(test_size, test_size, 2) |
| 42 | + b.ResetTimer() |
| 43 | + for i := 0; i < b.N; i++ { |
| 44 | + math.MatmulTiling(ma, mb, 24) |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +func BenchmarkMatMulTiling32(b *testing.B) { |
| 49 | + ma := testhelper.GenMat(test_size, test_size, 1) |
| 50 | + mb := testhelper.GenMat(test_size, test_size, 2) |
| 51 | + b.ResetTimer() |
| 52 | + for i := 0; i < b.N; i++ { |
| 53 | + math.MatmulTiling(ma, mb, 32) |
| 54 | + } |
| 55 | +} |
0 commit comments