Skip to content

Instantly share code, notes, and snippets.

@OlegJakushkin
Created June 4, 2016 01:38
Show Gist options
  • Save OlegJakushkin/2a2cb41333a10dbd9214b51bfd598f66 to your computer and use it in GitHub Desktop.
Save OlegJakushkin/2a2cb41333a10dbd9214b51bfd598f66 to your computer and use it in GitHub Desktop.
#include <vector>
#include <algorithm>
#include <random>
#include <cmath>
#include <functional>
#include <iostream>
#include <benchmark/benchmark.h>
#include <numeric>
#include <blond/trackers/sin.h>
using namespace std;
static void BM_sin_default(benchmark::State& state) {
int data_size = state.range_x();
double lower_bound = 0;
double upper_bound = 1;
random_device device;
mt19937 engine(device());
uniform_real_distribution<double> distribution(lower_bound,upper_bound);
auto generator = bind(distribution, engine);
vector<double> data(data_size);
while (state.KeepRunning()) {
state.PauseTiming();
generate(begin(data), end(data), generator);
state.ResumeTiming();
#pragma omp parallel for
for(int i = 0; i < data_size; ++i) {
data[i] = sin(data[i]);
}
}
cout << accumulate(data.begin(), data.end(), 0) << endl;
}
BENCHMARK(BM_sin_default)->RangeMultiplier(2)->Range(8, 8<<20);
static void BM_sin_fast(benchmark::State& state) {
int data_size = state.range_x();
double lower_bound = 0;
double upper_bound = 1;
random_device device;
mt19937 engine(device());
uniform_real_distribution<double> distribution(lower_bound, upper_bound);
auto generator = bind(distribution, engine);
vector<double> data(data_size);
while (state.KeepRunning()) {
state.PauseTiming();
generate(begin(data), end(data), generator);
state.ResumeTiming();
#pragma omp parallel for
for(int i = 0; i < data_size; ++i) {
data[i] = blond::vdt::fast_sin(data[i]);
}
}
cout << accumulate(data.begin(), data.end(), 0) << endl;
}
BENCHMARK(BM_sin_fast)->RangeMultiplier(2)->Range(8, 8 <<20);
BENCHMARK_MAIN();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment