53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
#include <algorithm>
|
|
#include <alsk/alsk.h>
|
|
|
|
constexpr unsigned benchN = 32;
|
|
constexpr int benchMin = -250;
|
|
constexpr int benchMax = +250;
|
|
|
|
constexpr unsigned benchVSize = 1'000'000;
|
|
|
|
/**
|
|
* Functions
|
|
*/
|
|
namespace bench {
|
|
|
|
using C = std::vector<int>;
|
|
|
|
struct Task {
|
|
std::size_t size;
|
|
|
|
auto operator()(int min, int max) {
|
|
C v(size);
|
|
std::generate_n(std::begin(v), size, [&, i=0]() mutable { return (++i)%(max-min+1) + min; });
|
|
return v;
|
|
};
|
|
};
|
|
|
|
C select(C const& a, C const& b) {
|
|
C::value_type sumA = std::accumulate(std::begin(a), std::end(a), C::value_type{});
|
|
C::value_type sumB = std::accumulate(std::begin(b), std::end(b), C::value_type{});
|
|
|
|
return sumA < sumB? a : b;
|
|
}
|
|
|
|
}
|
|
|
|
using namespace alsk::arg;
|
|
using tmp::Pack;
|
|
|
|
using SkelFarmSel = alsk::FarmSel<
|
|
R<1>(int, int),
|
|
Pack<bench::Task, bench::C(P<0>, P<1>)>,
|
|
Pack<decltype(&bench::select), bench::C(bench::C const&, bench::C const&)>
|
|
>;
|
|
|
|
int main() {
|
|
auto farmSel = alsk::implement<alsk::exec::Sequential, SkelFarmSel>();
|
|
farmSel.skeleton.task = bench::Task{benchVSize};
|
|
farmSel.skeleton.select = bench::select;
|
|
farmSel.skeleton.n = benchN;
|
|
|
|
auto volatile r = farmSel(benchMin, benchMax);
|
|
}
|