Commit f143a3c7 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

DRY some common code in folly/gen/test/ParallelBenchmark.cpp

Summary: [Folly] DRY some common code in `folly/gen/test/ParallelBenchmark.cpp`.

Reviewed By: Orvid

Differential Revision: D9664846

fbshipit-source-id: adf198a60ab637e47986ddea9c5c4e7392cf8b27
parent f169a842
......@@ -53,24 +53,23 @@ static auto isPrimeSlow = [](int n) {
static auto primes =
seq(1, 1 << 20) | filter(isPrimeSlow) | as<vector>();
static auto stopc(int n) {
return [=](int d) { return d * d > n; };
}
static auto divides(int n) {
return [=](int d) { return 0 == n % d; };
}
static auto isPrime = [](int n) {
return from(primes)
| until([&](int d) { return d * d > n; })
| filter([&](int d) { return 0 == n % d; })
| isEmpty;
return from(primes) | until(stopc(n)) | filter(divides(n)) | isEmpty;
};
static auto factors = [](int n) {
return from(primes)
| until([&](int d) { return d * d > n; })
| filter([&](int d) { return 0 == n % d; })
| count;
return from(primes) | until(stopc(n)) | filter(divides(n)) | count;
};
static auto factorsSlow = [](int n) {
return from(primes)
| filter([&](int d) { return 0 == n % d; })
| count;
return from(primes) | filter(divides(n)) | count;
};
static auto sleepyWork = [](int i) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment