I would like to create a macro that calls other macros. The macro, which I would call, is a macro Benchmarkfrom folly .
Ultimately, I would like to have a bunch of macros that look like this:
BENCHMARK(filter_10_vector_1_filter, n) { ... }
BENCHMARK(filter_10_set_1_filter, n) { ... }
BENCHMARK(filter_10_vector_2_filter, n) { ... }
BENCHMARK(filter_10_set_2_filter, n) { ... }
BENCHMARK(filter_10_vector_3_filter, n) { ... }
BENCHMARK(filter_10_set_3_filter, n) { ... }
... all the way to 10_filter
BENCHMARK(filter_100_vector_1_filter, n) { ... }
BENCHMARK(filter_100_set_1_filter, n) { ... }
... all the way to 10_filter
I tried to create a macro that looks like this:
#define CreateBenchmark(numElements, numFilters) \
BENCHMARK(filter_#
BENCHMARK_RELATIVE(filter_#
CreateBenchmark(10, 2);
which we hope will halve the number of macros I need to write. However, replacement ##numElementsand ##numFiltersdo not happen as I had hoped. The result of the call CreateBenchmark(10, 2)is
FilterWithSetBenchmark.cpp relative time/iter iters/s
filter_numElements_vector_numFilters_filters 264.35us 3.78K
filter_numElements_set_numFilters_filters 99.93% 264.54us 3.78K
I expected filter_10_vector_2_filtersand fitler_10_set_2_filters. Is there a way to pass the values provided to the macro CreateBenchmarkto the values passed to Benchmarkand calls BENCHMARK_RELATIVE?
CreateBenchmark for XX_filters, CreateBenchmark 20 (10 _vector_ 10 _set_)