I am writing a program that calculates the time it takes to sort a vector.
There's multiple sorters and I want to be able to call them all from the same function.
Here's on of the sorter itself.
Please note that the sorter has to be generic.
SelectionSort.h
template <typename T>
void selectionSort(T& v){
if(!v.empty()){
size_t iMin;
for(size_t i = 0; i < v.size(); ++i){
iMin = i;
for(size_t j = i + 1; j < v.size();++j){
if (v[j] < v[iMin])
iMin = j;
}
std::swap(v[i], v[iMin]);
}
}
}
Here's the part where I calculate the time it takes to sort.
In that case I want it to be a vector of int.
timeCalculation.cpp
typedef std::vector<int> V;
template <typename Fn>
std::chrono::duration<double, std::milli>
mesureTemps(Fn f,V &v1, unsigned iter) {
std::chrono::duration<double, std::milli> tempsTot{};
for(unsigned i = 0; i < iter; ++i) {
std::shuffle(v1.begin(),v1.end(),std::rand());
auto t1 = std::chrono::high_resolution_clock::now();
f(v1);
auto t2 = std::chrono::high_resolution_clock::now();
tempsTot += (t2 - t1);
}
return tempsTot /= iter;
}
int main() {
std::vector<int> v(N);
std::iota(v.begin(),v.end(),1);
auto tempsMoyen = mesureTemps(selectionSort, v,
10);
std::cout << tempsMoyen.count();
return EXIT_SUCCESS;
}
I cannot find a way to call mesureTemps without breaking at compilation.