* Benchmarks a given matrix multiply operation. * * The multiply is given here as a callback to try to keep Clang from folding, * unrolling, or inlining inconsistently across each benchmarked implementation. * We want Clang to do as much as possible to optimize *within* the multiply * function itself, but inconsistent optimization of the benchmark code itself * could skew results. * * @par
| 48 | * @return The average duration per call in nanoseconds. |
| 49 | */ |
| 50 | [[nodiscard, clang::noinline]] std::chrono::nanoseconds Benchmark( |
| 51 | Vec4<>& position, Mat4<>& translation, |
| 52 | std::function<Vec4<>(const Vec4<>&, const Mat4<>&)> func) { |
| 53 | // TODO: Move to a unit test. |
| 54 | auto test = func(position, translation); |
| 55 | auto expected = Vec4{{20, 10, 10, 1}}; |
| 56 | CHECK_EQ(test, expected); |
| 57 | |
| 58 | auto begin = std::chrono::steady_clock::now(); |
| 59 | |
| 60 | // This is another attempt to prevent Clang from optimizing the benchmark |
| 61 | // harness inconsistently. |
| 62 | #pragma clang loop unroll(disable) |
| 63 | for (auto i = 0U; i < kNumRuns; i++) { |
| 64 | result = func(position, translation); |
| 65 | } |
| 66 | |
| 67 | auto end = std::chrono::steady_clock::now(); |
| 68 | |
| 69 | return (end - begin) / kNumRuns; |
| 70 | } |
| 71 | |
| 72 | [[nodiscard]] std::expected<std::chrono::nanoseconds, BenchmarkError> |
| 73 | BenchmarkMatrixMultiplication(Backend backend) { |
no outgoing calls
no test coverage detected