Total Articles 180
[Windows]
#include <windows.h> DWORD begTick = GetTickCount(); foo(); DWORD endTick = GetTickCount(); printf("%d\n", endTick - begTick);
[Linux]
#include <sys/time.h> struct timeval begTick; gettimeofday(&begTick, NULL); foo(); struct timeval endTick; gettimeofday(&endTick, NULL); printf("%ld\n", (endTick.tv_sec - begTick.tv_sec) * 1000 + (endTick.tv_usec - begTick.tv_usec) / 1000);
[Boost]
#include <boost/date_time/posix_time/posix_time.hpp> boost::posix_time::ptime begTick(boost::posix_time::microsec_clock::local_time()); foo(); boost::posix_time::ptime endTick(boost::posix_time::microsec_clock::local_time()); std::cout << boost::posix_time::to_simple_string(endTick - begTick) << std::endl;