112 lines
2.6 KiB
C++
112 lines
2.6 KiB
C++
#include <celero/Celero.h>
|
|
#include <alsk/alsk.h>
|
|
|
|
#include "common.h"
|
|
|
|
using namespace bench;
|
|
using namespace alsk::edsl;
|
|
using namespace alsk::arg;
|
|
|
|
constexpr unsigned samples = 10, iterations = 100, cores = 4;
|
|
|
|
constexpr std::size_t vecSize = 10'000;
|
|
constexpr unsigned n = 128;
|
|
constexpr int minValue = -250, maxValue = +250;
|
|
|
|
decltype(auto) hwFarmSel(int min, int max) {
|
|
Task task{vecSize};
|
|
Data best{};
|
|
|
|
if(n)
|
|
best = task(min, max);
|
|
for(std::size_t i = 1; i < n; ++i) {
|
|
Data current = task(min, max);
|
|
best = select(current, best);
|
|
}
|
|
|
|
return best;
|
|
}
|
|
|
|
decltype(auto) hwFarmSelSk(int min, int max) {
|
|
Task task{vecSize};
|
|
Data best{};
|
|
|
|
std::vector<Data> bests(n);
|
|
|
|
for(std::size_t i = 0; i < n; ++i)
|
|
bests[i] = task(min, max);
|
|
|
|
best = std::move(bests[0]);
|
|
for(std::size_t i = 1; i < n; ++i)
|
|
best = select(std::move(bests[i-1]), std::move(best));
|
|
|
|
return best;
|
|
}
|
|
|
|
decltype(auto) hwFarmSelPar(int min, int max) {
|
|
Task task{vecSize};
|
|
Data best{};
|
|
|
|
std::vector<Data> bests(n);
|
|
|
|
#pragma omp parallel for num_threads(cores)
|
|
for(std::size_t i = 0; i < n; ++i)
|
|
bests[i] = task(min, max);
|
|
|
|
best = std::move(bests[0]);
|
|
for(std::size_t i = 1; i < n; ++i)
|
|
best = select(std::move(bests[i-1]), std::move(best));
|
|
|
|
return best;
|
|
}
|
|
|
|
constexpr auto eFarmSel = link<R<1>(int, int)>(n * link<Data(P<0>, P<1>)>(eTask)) ->* eSelect;
|
|
constexpr auto eFarmSelStdFun = link<R<1>(int, int)>(n * link<Data(P<0>, P<1>)>(eTaskStdFun)) ->* eSelectStdFun;
|
|
|
|
BASELINE(FarmSel, Handwritten, samples, iterations) {
|
|
celero::DoNotOptimizeAway(
|
|
hwFarmSel(minValue, maxValue)
|
|
);
|
|
}
|
|
|
|
BENCHMARK(FarmSel, HandwrittenSk, samples, iterations) {
|
|
celero::DoNotOptimizeAway(
|
|
hwFarmSelSk(minValue, maxValue)
|
|
);
|
|
}
|
|
|
|
BENCHMARK(FarmSel, Skeleton, samples, iterations) {
|
|
auto farmSel = alsk::edsl::implement<alsk::exec::Sequential>(eFarmSel);
|
|
farmSel.skeleton.task.size = vecSize;
|
|
|
|
celero::DoNotOptimizeAway(
|
|
farmSel(minValue, maxValue)
|
|
);
|
|
}
|
|
|
|
BENCHMARK(FarmSel, SkeletonStdFunction, samples, iterations) {
|
|
auto farmSel = alsk::edsl::implement<alsk::exec::Sequential>(eFarmSelStdFun);
|
|
farmSel.skeleton.task = Task{vecSize};
|
|
farmSel.skeleton.select = bench::select;
|
|
|
|
celero::DoNotOptimizeAway(
|
|
farmSel(minValue, maxValue)
|
|
);
|
|
}
|
|
|
|
BASELINE(FarmSelPar, Handwritten, samples, iterations) {
|
|
celero::DoNotOptimizeAway(
|
|
hwFarmSelPar(minValue, maxValue)
|
|
);
|
|
}
|
|
|
|
BENCHMARK(FarmSelPar, Skeleton, samples, iterations) {
|
|
auto farmSel = alsk::edsl::implement<alsk::exec::StaticThread>(eFarmSel);
|
|
farmSel.executor.cores = cores;
|
|
farmSel.skeleton.task.size = vecSize;
|
|
|
|
celero::DoNotOptimizeAway(
|
|
farmSel(minValue, maxValue)
|
|
);
|
|
}
|