1

I have written one function which is platform independent and working nicely in windows as well as linux. I wanted to check the execution time of that function. I am using QueryPerformanceCounter to calculate the execution time in windows and "gettimeofday" in linux. The problem is in windows the execution time is 60 mili seconds and in linux its showing 4 ms. Its a huge difference b/w them. Can anybody suggest what might went wrong....or If any body knows the some other APIs better than these to calculate elapsed time please let me know...

here is the code for i have written using gettimeofday......

void main()
{
    timeval start_time;
    timeval end_time;
    gettimeofday(&start_time,NULL);

              function_invoke(........);

    gettimeofday(&end_time,NULL);
    timeval res;
    timersub(&start_time,&end_time,&res);

    cout<<"function_invoke took seconds = "<<res.tv_sec<<endl;
    cout<<"function_invoke took microsec = "<<res.tv_usec<<endl;
}

OUTPUT :
    function_invoke took seconds = 0
    function_invoke took microsec = 4673 ( 4.673 mili seconds )     
Harish
  • 343
  • 1
  • 4
  • 14
  • If its an I/O operation Linux will be faster. – ismail Jan 09 '12 at 14:16
  • 60 ms vs. 4 ms is not all that big difference for some operations. Depending on what the function does that might just as well be correct results. – Jan Hudec Jan 09 '12 at 14:19
  • This could be heavily affected by what is happening on the machine at any given time as well, by nature windows will generally have more running in the background that could be competing with resources for this function depending on what its purpose is. I would say given a direct and equal comparison there is very little difference in the two OS considering their time source is likely the same HPET on chip, the variances will come more from resource management differences between the two. The difference is not a huge one unless it becomes a big scaling issue. – Sabre Jan 09 '12 at 14:44

0 Answers0