37 lines
704 B
C++
37 lines
704 B
C++
#include <celero/Celero.h>
|
|
#include <alsk/alsk.h>
|
|
|
|
constexpr unsigned samples = 20;
|
|
constexpr unsigned iterations = 500;
|
|
|
|
constexpr unsigned count = 1'000'000;
|
|
|
|
namespace {
|
|
|
|
unsigned r;
|
|
void *f(void * = nullptr) {
|
|
r = 0;
|
|
for(unsigned volatile i = 0; i < count; ++i) r += r;
|
|
return &r;
|
|
}
|
|
|
|
}
|
|
|
|
BASELINE(Thread, None, samples, iterations) {
|
|
celero::DoNotOptimizeAway(f());
|
|
}
|
|
|
|
BENCHMARK(Thread, cthread, samples, iterations) {
|
|
void *r;
|
|
pthread_t thread;
|
|
pthread_create(&thread, NULL, f, NULL);
|
|
pthread_join(thread, &r);
|
|
celero::DoNotOptimizeAway(r);
|
|
}
|
|
|
|
BENCHMARK(Thread, stdthread, samples, iterations) {
|
|
std::thread thread{f, nullptr};
|
|
thread.join();
|
|
celero::DoNotOptimizeAway(thread);
|
|
}
|