So, I'm just playing around implementing some sorting algorithms in C++, but I'm finding it irritating to benchmark them at the moment, due to the length of time it takes to not run the algorithm, but to create the input data. I currently test each length of input (1000, 2000, ...) 10 times, to gain a somewhat averaged time. For each of these 10 times, I create a new random vector
of the correct length, by doing:
// Each of the 10 times.
for(int j = 0; j < 10; j++) {
A.clear();
// 'i' is the current input size.
for(int k = 0; k < i; k++) {
A.push_back(rand() % 10000);
}
// Other stuff
}
Is there a better way to do this? Should I be bothering to cap the rand() at 10000, or is that just my OCD brain liking round numbers? (I.e., could that modulo operation actually be taking a serious amount of time when you consider it's performed up to - at the moment - 10,000 for each loop of the 10.) Alternatively, should I really create a new vector each time I run the sort? I've been doing so because I felt that it's possible that a created vector might be biased, and so if that one was generated and then used 10 times the answer might be quite off...