Skip to content

Instantly share code, notes, and snippets.

@shikharbhardwaj
Created July 23, 2017 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shikharbhardwaj/33daba392167f8752ac4bb9018c02e9d to your computer and use it in GitHub Desktop.
Save shikharbhardwaj/33daba392167f8752ac4bb9018c02e9d to your computer and use it in GitHub Desktop.
Micro benchmark for arma::shuffle
#include <benchmark/benchmark.h>
#include <algorithm>
#include <armadillo>
static void baseline(benchmark::State& state) {
while (state.KeepRunning()) {
arma::vec test(100, arma::fill::randn);
benchmark::DoNotOptimize(test);
}
}
static void arma_shuffle(benchmark::State& state) {
while (state.KeepRunning()) {
arma::vec test(100, arma::fill::randn);
test = std::move(arma::shuffle(test));
}
}
static void std_shuffle(benchmark::State& state) {
while (state.KeepRunning()) {
arma::vec test(100, arma::fill::randn);
std::random_shuffle(test.begin(), test.end());
}
}
BENCHMARK(baseline);
BENCHMARK(arma_shuffle);
BENCHMARK(std_shuffle);
BENCHMARK_MAIN();
λ mlpack_spike/random ∴ g++ shuffle_bench.cpp -O2 -Wall -std=c++11 -lbenchmark -larmadillo -pthread
λ mlpack_spike/random ∴ ./a.out
Run on (4 X 3660.03 MHz CPU s)
2017-07-23 23:20:32
Benchmark Time CPU Iterations
---------------------------------------------------
baseline 3472 ns 3472 ns 199661
arma_shuffle 8323 ns 8323 ns 83864
std_shuffle 5346 ns 5346 ns 126702
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment