Created
November 10, 2019 20:39
-
-
Save npetrenko/16863eb1578e4ee218794b6813a95c63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <benchmark/benchmark.h> | |
void LockedAdd(benchmark::State& state) { | |
unsigned int val; | |
while (state.KeepRunning()) { | |
asm volatile("lock addl $1, %[val]" : [val] "=m"(val)); | |
benchmark::DoNotOptimize(val); | |
} | |
} | |
void SimpleAdd(benchmark::State& state) { | |
unsigned int val; | |
while (state.KeepRunning()) { | |
asm volatile("addl $1, %[val]" : [val] "=m"(val)); | |
benchmark::DoNotOptimize(val); | |
} | |
} | |
BENCHMARK(LockedAdd); | |
BENCHMARK(SimpleAdd); | |
BENCHMARK_MAIN(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment