-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.cpp
More file actions
31 lines (28 loc) · 1.34 KB
/
benchmark.cpp
File metadata and controls
31 lines (28 loc) · 1.34 KB
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
#include <benchmark/benchmark.h>
#include "kstring.hpp"
constexpr const char * s = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
static void BM_StdStringCopy(benchmark::State& state) {
for (auto _ : state) {
std::string a{s};
for (auto i = 0; i < state.range(0); i++) {
std::string b{a};
}
}
state.SetBytesProcessed(int64_t(state.iterations()) *
int64_t(state.range(0)));
}
// Register the function as a benchmark
BENCHMARK(BM_StdStringCopy)->Arg(1<<10)->Arg(1<<11)->Arg(1<<12);
static void BM_KStringCopy(benchmark::State& state) {
for (auto _ : state) {
k::kastring a{s};
for (auto i = 0; i < state.range(0); i++) {
k::kastring b{a};
}
}
state.SetBytesProcessed(int64_t(state.iterations()) *
int64_t(state.range(0)));
}
// Register the function as a benchmark
BENCHMARK(BM_KStringCopy)->Arg(1<<10)->Arg(1<<11)->Arg(1<<12);
BENCHMARK_MAIN();