22 #define BENCHMARK_NOINLINE __attribute__((noinline))
24 #define BENCHMARK_NOINLINE
33 double CalculatePi(
int depth) {
36 double numerator =
static_cast<double>(((
i % 2) * 2) - 1);
37 double denominator =
static_cast<double>((2 *
i) - 1);
38 pi += numerator / denominator;
40 return (pi - 1.0) * 4;
43 std::set<int> ConstructRandomSet(
int size) {
45 for (
int i = 0;
i <
size; ++
i)
s.insert(
i);
49 std::mutex test_vector_mu;
50 std::vector<int>* test_vector =
nullptr;
75 static const int depth = 1024;
87 std::set<int>
data = ConstructRandomSet(state.
range(0));
89 for (
int j = 0; j < state.
range(1); ++j)
data.insert(rand());
96 template <
typename Container,
102 for (
int i = state.
range(0); --
i;) c.push_back(
v);
109 ->Range(1 << 0, 1 << 10);
112 #if __cplusplus >= 201103L
126 test_vector =
new std::vector<int>();
130 std::lock_guard<std::mutex> l(test_vector_mu);
132 test_vector->push_back(
i);
134 test_vector->pop_back();
144 double tracker = 0.0;
146 for (
int i = 0;
i < state.
range(0); ++
i)
153 int size = state.
range(0) /
static_cast<int>(
sizeof(int));
156 int to = from + thread_size;
159 test_vector =
new std::vector<int>(
size);
163 for (
int i = from;
i < to;
i++) {
177 size_t slept_for = 0;
178 int microseconds = state.
range(0);
179 std::chrono::duration<double, std::micro> sleep_duration{
180 static_cast<double>(microseconds)};
183 auto start = std::chrono::high_resolution_clock::now();
185 std::this_thread::sleep_for(
186 std::chrono::duration_cast<std::chrono::nanoseconds>(sleep_duration));
187 auto end = std::chrono::high_resolution_clock::now();
190 std::chrono::duration_cast<std::chrono::duration<double>>(
end -
start);
193 slept_for += microseconds;
200 #if __cplusplus >= 201103L
202 template <
class...
Args>
207 BENCHMARK_CAPTURE(BM_with_args, int_test, 42, 43, 44);
208 BENCHMARK_CAPTURE(BM_with_args, string_and_pair_test,
std::string(
"abc"),
209 std::pair<int, double>(42, 3.8));
214 BENCHMARK_CAPTURE(BM_non_template_args, basic_test, 0, 0);
216 #endif // __cplusplus >= 201103L
219 switch (st.
range(0)) {
231 assert(
false &&
"Invalid test case number");