Created
July 23, 2017 17:52
-
-
Save shikharbhardwaj/33daba392167f8752ac4bb9018c02e9d to your computer and use it in GitHub Desktop.
Micro benchmark for arma::shuffle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
λ 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