Does anyone now of a good way to use timers in C++? I've tried using clock_t, but it keeps returning 0:Code:clock_t start = clock(); //Do stuff.... clock_t end = clock(); double elapsed = static_cast<double>((end-start)/CLOCKS_PER_SEC);
This is a discussion on Timers within the C++ Programming forums, part of the General Programming Boards category; Does anyone now of a good way to use timers in C++? I've tried using clock_t, but it keeps returning ...
Does anyone now of a good way to use timers in C++? I've tried using clock_t, but it keeps returning 0:Code:clock_t start = clock(); //Do stuff.... clock_t end = clock(); double elapsed = static_cast<double>((end-start)/CLOCKS_PER_SEC);
Last edited by manutd; 11-19-2006 at 02:42 PM.
What is returning 0? Is it clock or your elapsed calculations? You should cast end-start to double and then perform the division. If you need more precision you should probably look into more platform specific timing mechanisms.
╔╗╔╦══╦╗╔╦══╦╗
║╚╝║╔╗║╚╝║╔╗║║
║╔╗║╠╣║╔╗║╠╣╠╣
╚╝╚╩╝╚╩╝╚╩╝╚╩╝
codez http://code.google.com/p/zxcvbn/
Elasped equals 0. Thanks for the tips, seperating the division worked.