Looking for replacement for clock() function

  • Thread starter Thread starter engri
  • Start date Start date
  • Tags Tags
    Clock Function
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
engri
Messages
4
Reaction score
0
This function seems to be working incorrectly when I run my programm under wine on linux system. (program compiled with mingw32 on win32) Is there any other function that can give me more accuracy than 1 second? (i know time() is working well but i need something that changes a little bit more frequent) Yes. I know I could compile it under linux but I need it to work under Wine right now.
 
Physics news on Phys.org
ok never mind. i included this function and now it works fine both under win32 and linux:

http://www.openasthra.com/c-tidbits/gettimeofday-function-for-windows/
 
Last edited by a moderator:
engri said:
This function seems to be working incorrectly when I run my programm under wine on linux system. (program compiled with mingw32 on win32) Is there any other function that can give me more accuracy than 1 second? (i know time() is working well but i need something that changes a little bit more frequent) Yes. I know I could compile it under linux but I need it to work under Wine right now.


You could always use the boost libraries to instantiate a boost::timer object.

Code:
#include <boost/timer.hpp>

...


// Create a boost::timer object
boost::timer timerObject;

// Something you want to time goes here
// ...

// Now calculate the elapsed time
std::cout << "Elapsed time = " << timerObject.elapsed << " sec.\n";