+
+BENCHMARK(minstdrand, n) {
+ BenchmarkSuspender braces;
+ std::random_device rd;
+ std::minstd_rand rng(rd());
+
+ braces.dismiss();
+
+ FOR_EACH_RANGE (i, 0, n) {
+ doNotOptimizeAway(rng());
+ }
+}
+
+BENCHMARK(mt19937, n) {
+ BenchmarkSuspender braces;
+ std::random_device rd;
+ std::mt19937 rng(rd());
+
+ braces.dismiss();
+
+ FOR_EACH_RANGE (i, 0, n) {
+ doNotOptimizeAway(rng());
+ }
+}
+
+BENCHMARK(threadprng, n) {
+ BenchmarkSuspender braces;
+ ThreadLocalPRNG tprng;
+ tprng();
+
+ braces.dismiss();
+
+ FOR_EACH_RANGE (i, 0, n) {
+ doNotOptimizeAway(tprng());
+ }
+}
+
+BENCHMARK(RandomDouble) { doNotOptimizeAway(Random::randDouble01()); }
+BENCHMARK(Random32) { doNotOptimizeAway(Random::rand32()); }
+BENCHMARK(Random32Num) { doNotOptimizeAway(Random::rand32(100)); }
+BENCHMARK(Random64) { doNotOptimizeAway(Random::rand64()); }
+BENCHMARK(Random64Num) { doNotOptimizeAway(Random::rand64(100ul << 32)); }
+BENCHMARK(Random64OneIn) { doNotOptimizeAway(Random::oneIn(100)); }
+
+int main(int argc, char** argv) {
+ testing::InitGoogleTest(&argc, argv);
+ gflags::ParseCommandLineFlags(&argc, &argv, true);
+
+ if (FLAGS_benchmark) {
+ folly::runBenchmarks();
+ }
+ return RUN_ALL_TESTS();
+}