Skip to content

Commit 2c8aa0e

Browse files
feat(google_benchmark): support arguments in URI
1 parent b563384 commit 2c8aa0e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

examples/google_benchmark/main.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <benchmark/benchmark.h>
2+
#include <cstring>
23

34
// Function to benchmark
45
static void BM_rand_vector(benchmark::State &state) {
@@ -20,4 +21,18 @@ static void BM_StringCopy(benchmark::State &state) {
2021
// Register the function as a benchmark
2122
BENCHMARK(BM_StringCopy);
2223

24+
static void BM_memcpy(benchmark::State &state) {
25+
char *src = new char[state.range(0)];
26+
char *dst = new char[state.range(0)];
27+
memset(src, 'x', state.range(0));
28+
for (auto _ : state)
29+
memcpy(dst, src, state.range(0));
30+
state.SetBytesProcessed(int64_t(state.iterations()) *
31+
int64_t(state.range(0)));
32+
delete[] src;
33+
delete[] dst;
34+
}
35+
36+
BENCHMARK(BM_memcpy)->Range(8, 8 << 10);
37+
2338
BENCHMARK_MAIN();

google_benchmark/src/benchmark_name.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616

1717
namespace benchmark {
1818

19+
#ifdef CODSPEED_INSTRUMENTATION
20+
BENCHMARK_EXPORT std::string BenchmarkName::str() const {
21+
if (args.empty()) {
22+
return function_name;
23+
}
24+
25+
return function_name + "[" + args + "]";
26+
}
27+
#else // COSPEED_INSTRUMENTATION
1928
namespace {
2029

2130
// Compute the total size of a pack of std::strings
@@ -56,4 +65,5 @@ std::string BenchmarkName::str() const {
5665
return join('/', function_name, args, min_time, min_warmup_time, iterations,
5766
repetitions, time_type, threads);
5867
}
68+
#endif
5969
} // namespace benchmark

0 commit comments

Comments
 (0)