Skip to content

Instantly share code, notes, and snippets.

@npetrenko
Created November 10, 2019 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npetrenko/16863eb1578e4ee218794b6813a95c63 to your computer and use it in GitHub Desktop.
Save npetrenko/16863eb1578e4ee218794b6813a95c63 to your computer and use it in GitHub Desktop.
#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