#include #include #include "dnautil.h" // N.B. This program can cause an Illegal Instruction fault if the CPU executing // the program does not support the relevant instruction (e.g., AVX2 or AVX512 instructions). // Investigate how you can perform a syscall at runtime to determine if the necessary AVX2 // or AVX512 instructions are supported before calling those functions. A general strategy // is to call this once, at runtime, during a setup phase and then use the 'fastest' // implementation supported by the architecture executing the code. static void BM_HammingDistance(benchmark::State& state) { std::random_device dev; std::mt19937 rng(dev()); auto pool = dnautil::RandomOligoPool(2); auto o1 = pool[0]; auto o2 = pool[1]; dnautil::HammingDistance distance; for (auto _ : state) { benchmark::DoNotOptimize(distance(o1, o2)); } } // Register the function as a benchmark BENCHMARK(BM_HammingDistance); static void BM_HammingDistanceAVX2(benchmark::State& state) { std::random_device dev; std::mt19937 rng(dev()); auto pool = dnautil::RandomOligoPool(2); auto o1 = pool[0]; auto o2 = pool[1]; dnautil::HammingDistanceAVX2 distance; for (auto _ : state) { benchmark::DoNotOptimize(distance(o1, o2)); } } // Register the function as a benchmark BENCHMARK(BM_HammingDistanceAVX2); static void BM_HammingDistanceAVX512(benchmark::State& state) { std::random_device dev; std::mt19937 rng(dev()); auto pool = dnautil::RandomOligoPool(2); auto o1 = pool[0]; auto o2 = pool[1]; dnautil::HammingDistanceAVX512 distance; for (auto _ : state) { benchmark::DoNotOptimize(distance(o1, o2)); } } // Register the function as a benchmark BENCHMARK(BM_HammingDistanceAVX512); BENCHMARK_MAIN();