22 #include <glog/logging.h> 38 return n <= 1 ? 1 :
fib(n - 1) +
fib(n - 2);
45 for (
int d = 3; d * d <= n; d += 2) {
57 return [=](
int d) {
return d * d > n; };
60 return [=](
int d) {
return 0 == n % d; };
76 const auto sleepyTime = std::chrono::microseconds(100);
77 std::this_thread::sleep_for(sleepyTime);
127 return std::thread([=] {
129 (i + 0) * fibs / FLAGS_threads, (i + 1) * fibs / FLAGS_threads)
130 |
map([](
int) {
return fib(kFib); })
135 from(
threads) | [](std::thread &thread) { thread.join(); };
142 ============================================================================
144 ============================================================================
147 ----------------------------------------------------------------------------
150 ----------------------------------------------------------------------------
153 ----------------------------------------------------------------------------
158 ----------------------------------------------------------------------------
161 ----------------------------------------------------------------------------
162 seq(1, fibs) |
map([](
int) {
return fib(kFib); 1.49s 669.53m
163 seq(1, fibs) |
parallel(
map([](
int) {
return fi 1698.07% 87.96ms 11.37
164 [] {
auto threads =
seq(1,
int(FLAGS_threads)) 1571.16% 95.06ms 10.52
165 ----------------------------------------------------------------------------
166 ============================================================================
169 gflags::ParseCommandLineFlags(&argc, &argv,
true);
BENCH_GEN_REL(small|parallel(map(factorsSlow))|sum)
int main(int argc, char *argv[])
constexpr detail::Count count
From from(Container &source)
DEFINE_int32(threads, std::max(1,(int32_t) sysconf(_SC_NPROCESSORS_CONF)/2),"Num threads.")
Gen seq(Value first, Value last)
—— Concurrent Priority Queue Implementation ——
constexpr detail::Sum sum
std::vector< std::thread::id > threads
Gen range(Value begin, Value end)
constexpr detail::IsEmpty< true > isEmpty
Map map(Predicate pred=Predicate())
static map< string, int > m
Parallel parallel(Ops ops, size_t threads=0)
BENCH_GEN(small|map(factorsSlow)|sum)
Filter filter(Predicate pred=Predicate())
constexpr detail::Concat concat
Until until(Predicate pred=Predicate())
static auto divides(int n)
detail::Take take(Number count)
Chunked chunked(const Container &container, int chunkSize=256)
std::chrono::nanoseconds time()