proxygen
ParallelTest.cpp File Reference
#include <array>
#include <iostream>
#include <memory>
#include <vector>
#include <glog/logging.h>
#include <folly/gen/Base.h>
#include <folly/gen/Parallel.h>
#include <folly/portability/GTest.h>

Go to the source code of this file.

Functions

 TEST (ParallelTest, Serial)
 
 TEST (ParallelTest, ComputeBound64)
 
 TEST (ParallelTest, Take)
 
 TEST (ParallelTest, Unique)
 
 TEST (ParallelTest, PSum)
 
int main (int argc, char *argv[])
 

Variables

const auto square = [](int i) { return i * i; }
 
const auto even = [](int i) { return 0 == i % 2; }
 
static auto sleepyWork
 
static auto isPrime
 
struct {
makeUnique
 
static auto primes = seq(1, 1 << 14) | filter(isPrime) | as<vector<size_t>>()
 
static auto primeFactors
 
auto heavyWork = map(primeFactors)
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 108 of file ParallelTest.cpp.

References testing::InitGoogleTest(), and RUN_ALL_TESTS().

108  {
110  gflags::ParseCommandLineFlags(&argc, &argv, true);
111  return RUN_ALL_TESTS();
112 }
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2232
char ** argv
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:5370
TEST ( ParallelTest  ,
Serial   
)

Definition at line 66 of file ParallelTest.cpp.

References even, EXPECT_EQ, folly::gen::filter(), folly::gen::map(), folly::gen::parallel(), folly::gen::seq(), square, and folly::gen::sum.

66  {
67  EXPECT_EQ(
68  seq(1, 10) | map(square) | filter(even) | sum,
69  seq(1, 10) | parallel(map(square) | filter(even)) | sum);
70 }
const auto even
std::atomic< int64_t > sum(0)
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
const auto square
static Map map(mapCap)
Parallel parallel(Ops ops, size_t threads=0)
Definition: Parallel.h:88
TEST ( ParallelTest  ,
ComputeBound64   
)

Definition at line 74 of file ParallelTest.cpp.

References EXPECT_EQ, heavyWork, folly::gen::parallel(), and folly::gen::sum.

74  {
75  int length = 1 << 10;
76  EXPECT_EQ(
77  seq<size_t>(1, length) | heavyWork | sum,
78  seq<size_t>(1, length) | parallel(heavyWork) | sum);
79 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
auto heavyWork
Parallel parallel(Ops ops, size_t threads=0)
Definition: Parallel.h:88
TEST ( ParallelTest  ,
Take   
)

Definition at line 81 of file ParallelTest.cpp.

References folly::gen::count, EXPECT_EQ, heavyWork, folly::gen::parallel(), folly::gen::seq(), and folly::gen::take().

81  {
82  int length = 1 << 18;
83  int limit = 1 << 14;
84  EXPECT_EQ(
85  seq(1, length) | take(limit) | count,
86  seq(1, length) | parallel(heavyWork) | take(limit) | count);
87 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
auto heavyWork
Parallel parallel(Ops ops, size_t threads=0)
Definition: Parallel.h:88
int * count
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( ParallelTest  ,
Unique   
)

Definition at line 89 of file ParallelTest.cpp.

References folly::gen::count, folly::gen::dereference, EXPECT_EQ, folly::gen::from(), makeUnique, folly::gen::map(), folly::gen::parallel(), primes, and folly::gen::take().

89  {
90  auto uniqued = from(primes) | map(makeUnique) | as<vector>();
91  EXPECT_EQ(
92  primes.size(),
95  EXPECT_EQ(
96  2,
99  count);
100 }
struct @64 makeUnique
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static auto primes
static Map map(mapCap)
Parallel parallel(Ops ops, size_t threads=0)
Definition: Parallel.h:88
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
int * count
detail::Take take(Number count)
Definition: Base-inl.h:2582
constexpr detail::Dereference dereference
Definition: Base-inl.h:2575
TEST ( ParallelTest  ,
PSum   
)

Definition at line 102 of file ParallelTest.cpp.

References EXPECT_EQ, folly::gen::from(), folly::gen::map(), folly::gen::parallel(), primes, sleepyWork, folly::gen::sub(), and folly::gen::sum.

102  {
103  EXPECT_EQ(
104  from(primes) | map(sleepyWork) | sum,
106 }
Sub sub(Sink sink)
Definition: Parallel.h:104
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static auto primes
static auto sleepyWork
static Map map(mapCap)
Parallel parallel(Ops ops, size_t threads=0)
Definition: Parallel.h:88
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from

Variable Documentation

const auto even = [](int i) { return 0 == i % 2; }

Definition at line 33 of file ParallelTest.cpp.

Referenced by TEST().

auto heavyWork = map(primeFactors)

Definition at line 72 of file ParallelTest.cpp.

Referenced by TEST().

auto isPrime
static
Initial value:
= [](int n) {
if (n < 2) {
return false;
} else if (n > 2) {
for (int d = 3; d * d <= n; d += 2) {
if (0 == n % d) {
return false;
}
}
}
return true;
}

Definition at line 40 of file ParallelTest.cpp.

struct { ... } makeUnique

Referenced by TEST().

auto primeFactors
static
Initial value:
= [](int n) {
return from(primes) | filter([&](int d) { return 0 == n % d; }) | count;
}
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
static auto primes
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
int * count

Definition at line 62 of file ParallelTest.cpp.

auto primes = seq(1, 1 << 14) | filter(isPrime) | as<vector<size_t>>()
static

Definition at line 60 of file ParallelTest.cpp.

Referenced by TEST().

auto sleepyWork
static
Initial value:
= [](int i) {
const auto sleepyTime = std::chrono::microseconds(100);
std::this_thread::sleep_for(sleepyTime);
return i;
}

Definition at line 34 of file ParallelTest.cpp.

Referenced by TEST().

const auto square = [](int i) { return i * i; }

Definition at line 32 of file ParallelTest.cpp.

Referenced by TEST().