proxygen
ParallelMapTest.cpp File Reference
#include <vector>
#include <glog/logging.h>
#include <folly/Memory.h>
#include <folly/gen/Base.h>
#include <folly/gen/ParallelMap.h>
#include <folly/portability/GTest.h>

Go to the source code of this file.

Functions

 TEST (Pmap, InfiniteEquivalent)
 
 TEST (Pmap, Empty)
 
 TEST (Pmap, Rvalues)
 
int main (int argc, char *argv[])
 

Function Documentation

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

Definition at line 157 of file ParallelMapTest.cpp.

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

157  {
159  gflags::ParseCommandLineFlags(&argc, &argv, true);
160  return RUN_ALL_TESTS();
161 }
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 ( Pmap  ,
InfiniteEquivalent   
)

Definition at line 29 of file ParallelMapTest.cpp.

References folly::gen::as(), EXPECT_EQ, folly::gen::map(), folly::gen::pmap(), folly::gen::seq(), folly::gen::until(), and x.

29  {
30  // apply
31  {
32  // clang-format off
33  auto mapResult
34  = seq(1)
35  | map([](int x) { return x * x; })
36  | until([](int x) { return x > 1000 * 1000; })
37  | as<std::vector<int>>();
38 
39  auto pmapResult
40  = seq(1)
41  | pmap([](int x) { return x * x; }, 4)
42  | until([](int x) { return x > 1000 * 1000; })
43  | as<std::vector<int>>();
44  // clang-format on
45 
46  EXPECT_EQ(pmapResult, mapResult);
47  }
48 
49  // foreach
50  {
51  // clang-format off
52  auto mapResult
53  = seq(1, 10)
54  | map([](int x) { return x * x; })
55  | as<std::vector<int>>();
56 
57  auto pmapResult
58  = seq(1, 10)
59  | pmap([](int x) { return x * x; }, 4)
60  | as<std::vector<int>>();
61  // clang-format on
62 
63  EXPECT_EQ(pmapResult, mapResult);
64  }
65 }
Definition: InvokeTest.cpp:58
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
Gen seq(Value first, Value last)
Definition: Base.h:484
static Map map(mapCap)
Until until(Predicate pred=Predicate())
Definition: Base.h:656
Collect as()
Definition: Base.h:811
PMap pmap(Predicate pred=Predicate(), size_t nThreads=0)
Definition: ParallelMap.h:42
TEST ( Pmap  ,
Empty   
)

Definition at line 67 of file ParallelMapTest.cpp.

References folly::gen::as(), EXPECT_EQ, folly::gen::map(), folly::gen::pmap(), folly::gen::seq(), folly::gen::until(), and x.

67  {
68  // apply
69  {
70  // clang-format off
71  auto mapResult
72  = seq(1)
73  | map([](int x) { return x * x; })
74  | until([](int) { return true; })
75  | as<std::vector<int>>();
76 
77  auto pmapResult
78  = seq(1)
79  | pmap([](int x) { return x * x; }, 4)
80  | until([](int) { return true; })
81  | as<std::vector<int>>();
82  // clang-format on
83 
84  EXPECT_EQ(mapResult.size(), 0);
85  EXPECT_EQ(pmapResult, mapResult);
86  }
87 
88  // foreach
89  {
90  // clang-format off
91  auto mapResult
92  = empty<int>()
93  | map([](int x) { return x * x; })
94  | as<std::vector<int>>();
95 
96  auto pmapResult
97  = empty<int>()
98  | pmap([](int x) { return x * x; }, 4)
99  | as<std::vector<int>>();
100  // clang-format on
101 
102  EXPECT_EQ(mapResult.size(), 0);
103  EXPECT_EQ(pmapResult, mapResult);
104  }
105 }
Definition: InvokeTest.cpp:58
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
Gen seq(Value first, Value last)
Definition: Base.h:484
static Map map(mapCap)
Until until(Predicate pred=Predicate())
Definition: Base.h:656
Collect as()
Definition: Base.h:811
PMap pmap(Predicate pred=Predicate(), size_t nThreads=0)
Definition: ParallelMap.h:42
TEST ( Pmap  ,
Rvalues   
)

Definition at line 107 of file ParallelMapTest.cpp.

References EXPECT_EQ, folly::gen::map(), folly::gen::pmap(), folly::gen::seq(), folly::gen::sum, folly::gen::take(), and x.

107  {
108  // apply
109  {
110  // clang-format off
111  auto mapResult
112  = seq(1)
113  | map([](int x) { return std::make_unique<int>(x); })
114  | map([](std::unique_ptr<int> x) {
115  return std::make_unique<int>(*x * *x); })
116  | map([](std::unique_ptr<int> x) { return *x; })
117  | take(1000)
118  | sum;
119 
120  auto pmapResult
121  = seq(1)
122  | pmap([](int x) { return std::make_unique<int>(x); })
123  | pmap([](std::unique_ptr<int> x) {
124  return std::make_unique<int>(*x * *x); })
125  | pmap([](std::unique_ptr<int> x) { return *x; })
126  | take(1000)
127  | sum;
128  // clang-format on
129 
130  EXPECT_EQ(pmapResult, mapResult);
131  }
132 
133  // foreach
134  {
135  // clang-format off
136  auto mapResult
137  = seq(1, 1000)
138  | map([](int x) { return std::make_unique<int>(x); })
139  | map([](std::unique_ptr<int> x) {
140  return std::make_unique<int>(*x * *x); })
141  | map([](std::unique_ptr<int> x) { return *x; })
142  | sum;
143 
144  auto pmapResult
145  = seq(1, 1000)
146  | pmap([](int x) { return std::make_unique<int>(x); })
147  | pmap([](std::unique_ptr<int> x) {
148  return std::make_unique<int>(*x * *x); })
149  | pmap([](std::unique_ptr<int> x) { return *x; })
150  | sum;
151  // clang-format on
152 
153  EXPECT_EQ(pmapResult, mapResult);
154  }
155 }
Definition: InvokeTest.cpp:58
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
Gen seq(Value first, Value last)
Definition: Base.h:484
static Map map(mapCap)
detail::Take take(Number count)
Definition: Base-inl.h:2582
PMap pmap(Predicate pred=Predicate(), size_t nThreads=0)
Definition: ParallelMap.h:42