Hi,
My C++ project simply computes runtimes from a basic sort funtion.
When I compare the times, obtained from the use of difftime and obtained from the time command, I observe a big difference and I don't understand why. Could someone explain me this point ?
Thanks in advance :-)
Here is the code :
//
// main.cpp
// sortCPP
//
#include <iostream>
#include <list>
#include <cstdlib>
int main()
{
int n = 41000000;
time_t timer_start;
time(&timer_start);
// Fills a list
std::list<int> myList;
for(int i=0; i<n; i++)
myList.push_back(rand() % 100000);
time_t timer_mid;
time(&timer_mid);
// Sorts the list
myList.sort (std::less<int>());
time_t timer_end;
time(&timer_end);
std::cout << "total : " << difftime(timer_end,timer_start) << std::endl; // Displays 41s
std::cout << "generation : " << difftime(timer_mid,timer_start) << std::endl; // Displays 4s
std::cout << "sort : " << difftime(timer_end,timer_mid) << std::endl; // Displays 37s
return 0;
}