#include #include #include int suma1(int *begin, int *end) { int total = 0; asm volatile("0: cmp %0,%2 \n" " je 1f \n" " add $4,%0 \n" // esto se " add -4(%0),%1 \n" // ve raro " jmp 0b \n" "1: \n" : "+&r"(begin), "+&r"(total) : "r"(end) : "cc", "memory"); return total; } int suma2(int *begin, int *end) { int total = 0; asm volatile("0: cmp %0,%2 \n" " je 1f \n" " add (%0),%1 \n" // ahora no, " add $4,%0 \n" // verdad? " jmp 0b \n" "1: \n" : "+&r"(begin), "+&r"(total) : "r"(end) : "cc", "memory"); return total; } template static void test(benchmark::State &state) { const std::size_t N = 1'000'000; int v[N]; long int suma = 0; std::iota(v, v + N, 0); for (auto _ : state) benchmark::DoNotOptimize(suma += f(v, v + N)); state.SetLabel(std::to_string(suma)); } BENCHMARK(test)->Iterations(2'000); BENCHMARK(test)->Iterations(2'000); BENCHMARK_MAIN();