proxygen
RandomBenchmark.cpp File Reference
#include <folly/Random.h>
#include <random>
#include <thread>
#include <glog/logging.h>
#include <folly/Benchmark.h>
#include <folly/container/Foreach.h>

Go to the source code of this file.

Functions

 BENCHMARK (minstdrand, n)
 
 BENCHMARK (mt19937, n)
 
 BENCHMARK (threadprng, n)
 
 BENCHMARK (RandomDouble)
 
 BENCHMARK (Random32)
 
 BENCHMARK (Random32Num)
 
 BENCHMARK (Random64)
 
 BENCHMARK (Random64Num)
 
 BENCHMARK (Random64OneIn)
 
int main (int argc, char **argv)
 

Function Documentation

BENCHMARK ( minstdrand  ,
 
)

Definition at line 33 of file RandomBenchmark.cpp.

References folly::BenchmarkSuspender::dismiss(), folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, rd, and rng.

33  {
34  BenchmarkSuspender braces;
35  std::random_device rd;
36  std::minstd_rand rng(rd());
37 
38  braces.dismiss();
39 
40  FOR_EACH_RANGE (i, 0, n) { doNotOptimizeAway(rng()); }
41 }
auto rng
Definition: CollectTest.cpp:31
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
std::random_device rd
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( mt19937  ,
 
)

Definition at line 43 of file RandomBenchmark.cpp.

References folly::BENCHMARK(), folly::BenchmarkSuspender::dismiss(), folly::doNotOptimizeAway(), FOR_EACH_RANGE, i, rd, and rng.

43  {
44  BenchmarkSuspender braces;
45  std::random_device rd;
46  std::mt19937 rng(rd());
47 
48  braces.dismiss();
49 
50  FOR_EACH_RANGE (i, 0, n) { doNotOptimizeAway(rng()); }
51 }
auto rng
Definition: CollectTest.cpp:31
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
std::random_device rd
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( threadprng  ,
 
)

Definition at line 65 of file RandomBenchmark.cpp.

References folly::BenchmarkSuspender::dismiss(), folly::doNotOptimizeAway(), FOR_EACH_RANGE, and i.

65  {
66  BenchmarkSuspender braces;
67  ThreadLocalPRNG tprng;
68  tprng();
69 
70  braces.dismiss();
71 
72  FOR_EACH_RANGE (i, 0, n) { doNotOptimizeAway(tprng()); }
73 }
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( RandomDouble  )

Definition at line 75 of file RandomBenchmark.cpp.

References folly::doNotOptimizeAway(), and folly::Random::randDouble01().

75  {
76  doNotOptimizeAway(Random::randDouble01());
77 }
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( Random32  )

Definition at line 78 of file RandomBenchmark.cpp.

References folly::doNotOptimizeAway(), and folly::Random::rand32().

78  {
79  doNotOptimizeAway(Random::rand32());
80 }
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( Random32Num  )

Definition at line 81 of file RandomBenchmark.cpp.

References folly::doNotOptimizeAway(), and folly::Random::rand32().

81  {
82  doNotOptimizeAway(Random::rand32(100));
83 }
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( Random64  )

Definition at line 84 of file RandomBenchmark.cpp.

References folly::doNotOptimizeAway(), and folly::Random::rand64().

84  {
85  doNotOptimizeAway(Random::rand64());
86 }
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( Random64Num  )

Definition at line 87 of file RandomBenchmark.cpp.

References folly::doNotOptimizeAway(), and folly::Random::rand64().

87  {
88  doNotOptimizeAway(Random::rand64(100ull << 32));
89 }
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( Random64OneIn  )

Definition at line 90 of file RandomBenchmark.cpp.

References folly::doNotOptimizeAway(), and folly::Random::oneIn().

90  {
91  doNotOptimizeAway(Random::oneIn(100));
92 }
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
int main ( int  argc,
char **  argv 
)

Definition at line 94 of file RandomBenchmark.cpp.

References folly::runBenchmarks().

94  {
95  gflags::ParseCommandLineFlags(&argc, &argv, true);
97  return 0;
98 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv