Created
June 4, 2016 01:38
-
-
Save OlegJakushkin/2a2cb41333a10dbd9214b51bfd598f66 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
| #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