aboutsummaryrefslogtreecommitdiff
path: root/experiments/matmul.cpp
diff options
context:
space:
mode:
authory-jan137 <yousefjan24000@gmail.com>2026-03-16 11:52:36 +0300
committery-jan137 <yousefjan24000@gmail.com>2026-03-16 11:52:36 +0300
commitb27583941c200f98ab328901e81c9188945bf708 (patch)
treec9b0c2bddb8d89e4398e6dbf2d787bea10cffaac /experiments/matmul.cpp
parent606ad99e8363bd520506ea2e88b831911fe03c18 (diff)
Cleanup
Diffstat (limited to 'experiments/matmul.cpp')
-rw-r--r--experiments/matmul.cpp15
1 files changed, 5 insertions, 10 deletions
diff --git a/experiments/matmul.cpp b/experiments/matmul.cpp
index 8ef0ac5..ed08c3c 100644
--- a/experiments/matmul.cpp
+++ b/experiments/matmul.cpp
@@ -49,12 +49,8 @@ Matrix naive_matmul(const Matrix& lhs, const Matrix& rhs) {
return result;
}
-// ---------------------------------------------------------------------------
-// Helpers
-// ---------------------------------------------------------------------------
+// --- Helpers ---
-// Fill an n×n matrix with a deterministic pattern so the compiler cannot
-// optimise multiplications away.
Matrix make_matrix(std::size_t n) {
Matrix M(n, n);
const double inv = 1.0 / static_cast<double>(n + 1);
@@ -98,7 +94,6 @@ int main() {
std::cout << " C = A * B, A and B both n×n\n";
std::cout << std::string(72, '*') << "\n\n";
- // Column header.
std::cout << std::left
<< std::setw(6) << "n"
<< std::setw(14) << "naive ms"
@@ -121,12 +116,12 @@ int main() {
(void)sink_simd;
const double t_naive = min_time_s([&] { (void)naive_matmul(A, B); }, trials);
- const double t_simd = min_time_s([&] { (void)(A * B); }, trials);
+ const double t_simd = min_time_s([&] { (void)(A * B); }, trials);
- const double fp = flops(n);
+ const double fp = flops(n);
const double gf_naive = fp / t_naive / 1e9;
- const double gf_simd = fp / t_simd / 1e9;
- const double speedup = t_naive / t_simd;
+ const double gf_simd = fp / t_simd / 1e9;
+ const double speedup = t_naive / t_simd;
std::cout << std::left << std::setw(6) << n
<< std::fixed << std::setprecision(3)