Looking for replacement for clock() function

  • Thread starter Thread starter engri
  • Start date Start date
  • Tags Tags
    Clock Function
Click For Summary
SUMMARY

The discussion focuses on finding a replacement for the clock() function due to its inaccurate performance under Wine on Linux systems. Users recommend using the gettimeofday() function for improved accuracy, which works well across both Win32 and Linux environments. Additionally, the Boost libraries, specifically boost::timer, are suggested as a robust alternative for timing operations with higher precision.

PREREQUISITES
  • Understanding of C++ programming and its standard libraries
  • Familiarity with the Boost C++ Libraries
  • Knowledge of cross-platform development using Wine
  • Experience with timing functions in programming
NEXT STEPS
  • Research the gettimeofday() function and its implementation in C++
  • Explore the Boost libraries, focusing on boost::timer for performance measurement
  • Learn about cross-compilation techniques using MinGW on Linux
  • Investigate other high-resolution timing functions available in C++11 and later
USEFUL FOR

Software developers, particularly those working on cross-platform applications, performance analysts, and anyone needing precise timing mechanisms in their C++ programs.

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.
 
Technology 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";
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
Replies
6
Views
3K
  • · Replies 29 ·
Replies
29
Views
4K
  • · Replies 30 ·
2
Replies
30
Views
7K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 39 ·
2
Replies
39
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
7K
  • · Replies 12 ·
Replies
12
Views
2K