Last active
November 14, 2016 03:36
-
-
Save xaxxon/4746fd4950f4048dfc6a32e7e3c807d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// clang++ foo.cpp -std=c++14 -lbenchmark -O3 | |
// zacs-MacBook-Pro:~ xaxxon$ ./a.out | |
// Run on (4 X 3100 MHz CPU s) | |
// 2016-11-13 19:35:19 | |
// Benchmark Time CPU Iterations | |
// -------------------------------------------------------- | |
// list_iteration 19084 ns 19034 ns 34159 | |
// vec_ptr_iteration 6837 ns 6809 ns 98262 | |
#include <vector> | |
#include <list> | |
#include <string> | |
#include <benchmark/benchmark.h> | |
#include <memory> | |
#include <boost/pool/pool_alloc.hpp> | |
using namespace std; | |
static void list_iteration(benchmark::State& state) { | |
list<int> int_list; | |
for (int i = 0; i < 10000; i++) { | |
int_list.push_back(i); | |
} | |
while (state.KeepRunning()) { | |
for(int & i : int_list) { | |
benchmark::DoNotOptimize(i); | |
} | |
} | |
} | |
BENCHMARK(list_iteration); | |
static void vec_ptr_iteration(benchmark::State& state) { | |
vector<unique_ptr<int>> int_ptr_vec; | |
for (int i = 0; i < 10000; i++) { | |
int_ptr_vec.push_back(make_unique<int>(i)); | |
} | |
while (state.KeepRunning()) { | |
for(auto const & i : int_ptr_vec) { | |
benchmark::DoNotOptimize(*i); | |
} | |
} | |
} | |
// Register the function as a benchmark | |
BENCHMARK(vec_ptr_iteration); | |
BENCHMARK_MAIN(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment