Skip to content

Instantly share code, notes, and snippets.

@fearofcode
Created December 14, 2018 15:06
Show Gist options
  • Save fearofcode/560117add47ac9f786ef143d44fd4d8c to your computer and use it in GitHub Desktop.
Save fearofcode/560117add47ac9f786ef143d44fd4d8c to your computer and use it in GitHub Desktop.
Sample benchmark of PCG code
/*
Sample output:
12/14/18 07:05:12
Running neuroevolution.exe
Run on (8 X 3492 MHz CPU s)
CPU Caches:
L1 Data 32K (x4)
L1 Instruction 32K (x4)
L2 Unified 262K (x4)
L3 Unified 8388K (x1)
-------------------------------------------------------
Benchmark Time CPU Iterations
-------------------------------------------------------
BM_Standard_RNG 51 ns 52 ns 10000000
BM_PCG_RNG 2 ns 2 ns 280000000
*/
#include <iostream>
#include <random>
#include <benchmark/benchmark.h>
#include "pcg_random.hpp"
static void BM_Standard_RNG(benchmark::State& state) {
std::random_device rd;
std::uniform_int_distribution<int> mt_uniform_distribution(0, 1024);
for (auto _ : state) {
mt_uniform_distribution(rd);
}
}
BENCHMARK(BM_Standard_RNG);
static void BM_PCG_RNG(benchmark::State& state) {
pcg_extras::seed_seq_from<std::random_device> pcg_seed_source;
pcg32 rng(pcg_seed_source);
std::uniform_int_distribution<> pcg_uniform_distribution(0, 1024);
for (auto _ : state) {
pcg_uniform_distribution(rng);
}
}
BENCHMARK(BM_PCG_RNG);
BENCHMARK_MAIN();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment