/mb.cpp Secret
Created
November 25, 2024 00:26
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> | |
static void mfence_bench(benchmark::State& state) | |
{ | |
for (auto _ : state) { | |
__asm__ __volatile__("mfence" ::: "memory"); | |
} | |
} | |
static void add_stack(benchmark::State& state) | |
{ | |
for (auto _ : state) { | |
__asm__ __volatile__("lock addq $0, (%%rsp)" ::: "memory"); | |
} | |
} | |
static unsigned long shite_global; | |
static void add_global(benchmark::State& state) | |
{ | |
for (auto _ : state) { | |
__asm__ __volatile__("lock addq $0, %0" :: "m"(shite_global) : "memory"); | |
} | |
} | |
BENCHMARK(mfence_bench); | |
BENCHMARK(add_stack); | |
BENCHMARK(add_global); | |
BENCHMARK_MAIN(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment