#include #include #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 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 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(int, int)>(n * link, P<1>)>(eTask)) ->* eSelect; constexpr auto eFarmSelStdFun = link(int, int)>(n * link, 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(eFarmSel); farmSel.skeleton.task.size = vecSize; celero::DoNotOptimizeAway( farmSel(minValue, maxValue) ); } BENCHMARK(FarmSel, SkeletonStdFunction, samples, iterations) { auto farmSel = alsk::edsl::implement(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(eFarmSel); farmSel.executor.cores = cores; farmSel.skeleton.task.size = vecSize; celero::DoNotOptimizeAway( farmSel(minValue, maxValue) ); }