#include #include #include "pls/internal/scheduling/scheduler.h" #include "pls/internal/scheduling/parallel_result.h" #include "pls/internal/scheduling/scheduler_memory.h" using namespace pls::internal; constexpr size_t NUM_THREADS = 1; constexpr size_t NUM_TASKS = 64; constexpr size_t MAX_TASK_STACK_SIZE = 0; constexpr size_t NUM_CONTS = 64; constexpr size_t MAX_CONT_SIZE = 128; scheduling::parallel_result fib(int n) { if (n == 0) { return 0; } if (n == 1) { return 1; } return scheduling::scheduler::par([=]() { return fib(n - 1); }, [=]() { return fib(n - 2); }).then([](int a, int b) { return a + b; }); } int fib_normal(int n) { if (n == 0) { return 0; } if (n == 1) { return 1; } return fib_normal(n - 1) + fib_normal(n - 2); } int main() { scheduling::static_scheduler_memory static_scheduler_memory; scheduling::scheduler scheduler{static_scheduler_memory, NUM_THREADS}; auto start = std::chrono::steady_clock::now(); std::cout << "fib = " << fib_normal(39) << std::endl; auto end = std::chrono::steady_clock::now(); std::cout << "Normal: " << std::chrono::duration_cast(end - start).count() << std::endl; start = std::chrono::steady_clock::now(); scheduler.perform_work([]() { return scheduling::scheduler::par([]() { return fib(39); }, []() { return scheduling::parallel_result{0}; }).then([](int a, int b) { std::cout << "fib = " << a + b << std::endl; return a + b; }); }); end = std::chrono::steady_clock::now(); std::cout << "Framework: " << std::chrono::duration_cast(end - start).count() << std::endl; return 0; }