Witam.
Mam prosty program:
#include <cstdio>
#include <ctime>
#include <boost/timer.hpp>
int main(int argc, char **argv)
{
double dif1, dif2, dif3;
time_t start1, end1;
clock_t start2, end2;
boost::timer timeCnt;
time(&start1);
start2 = clock();
timeCnt.restart();
for(int i(0); i < 500000; i++)
{
printf("%d\n", i);
}
time(&end1);
end2 = clock();
dif1 = difftime(end1, start1);
dif2 = static_cast<double>(end2 - start2) / CLOCKS_PER_SEC;
dif3 = timeCnt.elapsed();
printf("Time 1 : %.2lf\n", dif1);
printf("Time 2 : %.2lf\n", dif2);
printf("Time 3 : %.2lf\n", dif3);
return 1;
}
W wyniku otrzymuję:
Time 1 : 9.00
Time 2 : 1.64
Time 3 : 1.64
Który z tych czasów jest prawidłowy? Skąd te różnice ?