[Assorted-commits] SF.net SVN: assorted:[1901] sandbox/trunk/src/cc/timing.cc
Brought to you by:
yangzhang
From: <yan...@us...> - 2017-05-12 21:58:43
|
Revision: 1901 http://sourceforge.net/p/assorted/svn/1901 Author: yangzhang Date: 2017-05-12 21:58:42 +0000 (Fri, 12 May 2017) Log Message: ----------- Add timing sandbox test Added Paths: ----------- sandbox/trunk/src/cc/timing.cc Added: sandbox/trunk/src/cc/timing.cc =================================================================== --- sandbox/trunk/src/cc/timing.cc (rev 0) +++ sandbox/trunk/src/cc/timing.cc 2017-05-12 21:58:42 UTC (rev 1901) @@ -0,0 +1,25 @@ +#include <ctime> +#include <iostream> +#include <sys/time.h> +#include <sys/timeb.h> +using namespace std; +unsigned long usec() { + timeval t; + gettimeofday(&t, 0); + return 1000000 * t.tv_sec + t.tv_usec; +} +int main() { + struct timeb start, end; + ftime(&start); + cout << time(0) << endl; + cout << clock() << endl; + cout << usec() << endl; + usleep(5000); + ftime(&end); + int diff = (int) (1000.0 * (end.time - start.time) + (end.millitm - start.millitm)); + cout << time(0) << endl; + cout << clock() << endl; + cout << usec() << endl; + cout << diff << endl; + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |