Repository: google/benchmark
File: include/benchmark/benchmark.h (C/C++)

Code before:
  static ::benchmark::internal::Benchmark const* const BENCHMARK_PRIVATE_NAME( \
      n) [[maybe_unused]]

#define BENCHMARK(...)                                                \
  BENCHMARK_PRIVATE_DECLARE(_benchmark_) =                            \
      (::benchmark::internal::RegisterBenchmarkInternal(              \
          std::make_unique<::benchmark::internal::FunctionBenchmark>( \
              #__VA_ARGS__, __VA_ARGS__)))

// Old-style macros
#define BENCHMARK_WITH_ARG(n, a) BENCHMARK(n)->Arg((a))
#define BENCHMARK_WITH_ARG2(n, a1, a2) BENCHMARK(n)->Args({(a1), (a2)})
#define BENCHMARK_WITH_UNIT(n, t) BENCHMARK(n)->Unit((t))
#define BENCHMARK_RANGE(n, lo, hi) BENCHMARK(n)->Range((lo), (hi))
#define BENCHMARK_RANGE2(n, l1, h1, l2, h2) \
  BENCHMARK(n)->RangePair({{(l1), (h1)}, {(l2), (h2)}})

// Register a benchmark which invokes the function specified by `func`
// with the additional arguments specified by `...`.
//
// For example:
//
// template <class ...ExtraArgs>`
// void BM_takes_args(benchmark::State& state, ExtraArgs&&... extra_args) {
//  [...]
//}
// /* Registers a benchmark named "BM_takes_args/int_string_test` */
// BENCHMARK_CAPTURE(BM_takes_args, int_string_test, 42, std::string("abc"));
#define BENCHMARK_CAPTURE(func, test_case_name, ...)                  \
  BENCHMARK_PRIVATE_DECLARE(_benchmark_) =                            \
      (::benchmark::internal::RegisterBenchmarkInternal(              \
          std::make_unique<::benchmark::internal::FunctionBenchmark>( \
              #func "/" #test_case_name,                              \
              [](::benchmark::State& st) { func(st, __VA_ARGS__); })))

// This will register a benchmark for a templatized function.  For example:
//
// template<int arg>
// void BM_Foo(int iters);
//
// BENCHMARK_TEMPLATE(BM_Foo, 1);
//
// will register BM_Foo<1> as a benchmark.
#define BENCHMARK_TEMPLATE1(n, a)                                     \
  BENCHMARK_PRIVATE_DECLARE(n) =                                      \
      (::benchmark::internal::RegisterBenchmarkInternal(              \
          std::make_unique<::benchmark::internal::FunctionBenchmark>( \
              #n "<" #a ">", n<a>)))

#define BENCHMARK_TEMPLATE2(n, a, b)                                  \
  BENCHMARK_PRIVATE_DECLARE(n) =                                      \

Review comment (bug):
I think there's a bug here: the macros should call `::benchmark::internal::make_unique` not `benchmark::internal::make_unique`.

We're now getting [compilation failures](https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-amd64-c6a-4xlarge-linux/builds/937#0195d209-e346-4c84-8895-b82b61d1a899/95-2687) because of this, example:
```
/var/lib/buildkite-agent/builds/amd64-c6a-4xlarge-linux-i-0a326a82268fb1cf0-1/apache-arrow/arrow-bci-benchmark-on-amd64-c6a-4xlarge-linux/arrow/cpp/src/parquet/page_index_benchmark.cc:60:1: error: 'parquet::benchmark::internal' has not been declared
   60 | BENCHMARK(BM_ReadOffsetIndex)->Apply(PageIndexSetArgs);
      | ^~~~~~~~~
```


Code after:
#else
#define BENCHMARK_PRIVATE_UNIQUE_ID __LINE__
#endif

// Helpers for generating unique variable names
#define BENCHMARK_PRIVATE_NAME(...)                                      \
  BENCHMARK_PRIVATE_CONCAT(benchmark_uniq_, BENCHMARK_PRIVATE_UNIQUE_ID, \
                           __VA_ARGS__)

#define BENCHMARK_PRIVATE_CONCAT(a, b, c) BENCHMARK_PRIVATE_CONCAT2(a, b, c)
#define BENCHMARK_PRIVATE_CONCAT2(a, b, c) a##b##c
// Helper for concatenation with macro name expansion
#define BENCHMARK_PRIVATE_CONCAT_NAME(BaseClass, Method) \
  BaseClass##_##Method##_Benchmark

#define BENCHMARK_PRIVATE_DECLARE(n)                                           \
  /* NOLINTNEXTLINE(misc-use-anonymous-namespace) */                           \
  static ::benchmark::internal::Benchmark const* const BENCHMARK_PRIVATE_NAME( \
      n) BENCHMARK_UNUSED

#define BENCHMARK(...)                                                \
  BENCHMARK_PRIVATE_DECLARE(_benchmark_) =                            \
      (::benchmark::internal::RegisterBenchmarkInternal(              \
          benchmark::internal::make_unique<                           \
              ::benchmark::internal::FunctionBenchmark>(#__VA_ARGS__, \
                                                        __VA_ARGS__)))

// Old-style macros
#define BENCHMARK_WITH_ARG(n, a) BENCHMARK(n)->Arg((a))
#define BENCHMARK_WITH_ARG2(n, a1, a2) BENCHMARK(n)->Args({(a1), (a2)})
#define BENCHMARK_WITH_UNIT(n, t) BENCHMARK(n)->Unit((t))
#define BENCHMARK_RANGE(n, lo, hi) BENCHMARK(n)->Range((lo), (hi))
#define BENCHMARK_RANGE2(n, l1, h1, l2, h2) \
  BENCHMARK(n)->RangePair({{(l1), (h1)}, {(l2), (h2)}})

// Register a benchmark which invokes the function specified by `func`
// with the additional arguments specified by `...`.
//
// For example:
//
// template <class ...ExtraArgs>`
// void BM_takes_args(benchmark::State& state, ExtraArgs&&... extra_args) {
//  [...]
//}
// /* Registers a benchmark named "BM_takes_args/int_string_test` */
// BENCHMARK_CAPTURE(BM_takes_args, int_string_test, 42, std::string("abc"));
#define BENCHMARK_CAPTURE(func, test_case_name, ...)     \
  BENCHMARK_PRIVATE_DECLARE(_benchmark_) =               \
      (::benchmark::internal::RegisterBenchmarkInternal( \
          benchmark::internal::make_unique<              \
              ::benchmark::internal::FunctionBenchmark>( \