Hi, I am just wondering if it is possible to achieve the following set up.
I usually have two functions that do the same job and I want to compare their performance, let's say for example I have two functions bubble_sort and merge_sort.
To do this I have to automatically generate an array of numbers to sort, So I have another function called rand_array(n) where n is the size of the array.
Then my test set up looks like:
static void BM_bubbleSort(benchmark::State &state)
{
auto a = rand_array(state.range(0));
while(state.keepRunning())
{
benchmark::DoNotOptimize(bubble_sort(a));l
}
state.SetCompexity(state.range(0));
}
static void BM_mergeSort(benchmark::State &state)
{
auto a = rand_array(state.range(0));
while(state.keepRunning())
{
benchmark::DoNotOptimize(merge_sort(a));l
}
state.SetCompexity(state.range(0));
}
Then I register these two benchmarks to run with a range of parameters, to test their big O.
But here is the thing, I want to test them against the same, but randomly generated data. So I am just wondering if I can only generate the array once and then use them in both these cases rather generate two sets of test cases, one for each benchmark.
Is that possible?
Thanks a lot!
Best,
Bob