MCPcopy Create free account
hub / github.com/android/ndk-samples / Benchmark

Function Benchmark

vectorization/src/main/cpp/benchmark.cpp:50–70  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

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>
73BenchmarkMatrixMultiplication(Backend backend) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected