Created
March 26, 2021 04:05
-
-
Save BillyONeal/e6b1e9640e5730b2da212bf6aba7966b to your computer and use it in GitHub Desktop.
future benchmark
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 <stdint.h> | |
#include <future> | |
#include <random> | |
#include <vector> | |
#include <benchmark/benchmark.h> | |
static uint_fast32_t long_running_task() { | |
std::mt19937 gen{std::random_device{}()}; | |
gen.discard(1000); | |
return gen(); | |
} | |
static void bench_async(benchmark::State& state) { | |
using namespace std; | |
for (auto _ : state) { | |
(void)_; | |
vector<future<uint_fast32_t>> futures(1000000); | |
for (auto& f : futures) { | |
f = async([] { return long_running_task(); }); | |
} | |
for (auto& f : futures) { | |
f.wait(); | |
} | |
} | |
} | |
BENCHMARK(bench_async); | |
BENCHMARK_MAIN(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment