aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/benchmark/src/benchmark_name.cc
blob: 01676bbc84df4233780c9c2ead89d31e5a70a930 (plain) (blame)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2015 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <benchmark/benchmark.h>

namespace benchmark {

namespace {

// Compute the total size of a pack of std::strings
size_t size_impl() { return 0; }

template <typename Head, typename... Tail>
size_t size_impl(const Head& head, const Tail&... tail) {
  return head.size() + size_impl(tail...);
}

// Join a pack of std::strings using a delimiter
// TODO: use absl::StrJoin
void join_impl(std::string&, char) {}

template <typename Head, typename... Tail>
void join_impl(std::string& s, const char delimiter, const Head& head,
               const Tail&... tail) {
  if (!s.empty() && !head.empty()) {
    s += delimiter;
  }

  s += head;

  join_impl(s, delimiter, tail...);
}

template <typename... Ts>
std::string join(char delimiter, const Ts&... ts) {
  std::string s;
  s.reserve(sizeof...(Ts) + size_impl(ts...));
  join_impl(s, delimiter, ts...);
  return s;
}
}  // namespace

BENCHMARK_EXPORT
std::string BenchmarkName::str() const {
  return join('/', function_name, args, min_time, min_warmup_time, iterations,
              repetitions, time_type, threads);
}
}  // namespace benchmark