-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmybenchlib_benchmark.cpp
More file actions
33 lines (25 loc) · 912 Bytes
/
mybenchlib_benchmark.cpp
File metadata and controls
33 lines (25 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <benchmark/benchmark.h>
#include "mybenchlib.hpp"
static void BM_BubbleSort(benchmark::State& state) {
auto sort_size = state.range(0);
std::vector<int> vec(static_cast<uint32_t>(sort_size));
for (auto _ : state) {
state.PauseTiming();
std::generate(vec.begin(), vec.end(), [] { return rand(); });
state.ResumeTiming();
BubbleSort(vec.data(), vec.size());
}
}
BENCHMARK(BM_BubbleSort)->RangeMultiplier(8)->Range(128, 1024);
static void BM_MergeSort(benchmark::State& state) {
auto sort_size = state.range(0);
std::vector<int> vec(static_cast<uint32_t>(sort_size));
for (auto _ : state) {
state.PauseTiming(); // 暂停计时
std::generate(vec.begin(), vec.end(), [] { return rand(); });
state.ResumeTiming(); // 恢复计时
MergeSort(vec.data(), vec.size());
}
}
BENCHMARK(BM_MergeSort)->RangeMultiplier(8)->Range(128, 1024);
BENCHMARK_MAIN();