#include #include #include #include int suma1(int *begin, int *end) { int total = 0; asm("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"); return total; } int suma2(int *begin, int *end) { int total = 0; asm("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"); return total; } int suma3(int *begin, int *end) { return std::accumulate(begin, end, 0); } template static void test(benchmark::State &state) { const std::size_t N = 1'000'000; std::array array; int resultado = 0; std::ranges::iota(array, 0); for (auto _ : state) resultado = f(array.begin(), array.end()); state.SetLabel(std::to_string(resultado)); } BENCHMARK(test)->Unit(benchmark::kMicrosecond); BENCHMARK(test)->Unit(benchmark::kMicrosecond); BENCHMARK(test)->Unit(benchmark::kMicrosecond); BENCHMARK_MAIN();