Hi,
I need to time a process within my c++ program, to the finest/lowest level possible (i.e. the smallest fraction of a second possible).
I am running my program on a Sun Solaris UNIX machine, and compiling it with g++. I am unable to get what should(?) be simple code to return a meaningful answer. example:
When I run this, I invariably get
elapsed time: .0.
,even if I put a "sleep(2)" etc. in the process...
This is very frustrating. I've tried various permutations with time_t t = clock() etc. and all produce the same result.
Any help would be greatly appreciated, as I'm about at my wits end.
Thank you,
dora
I need to time a process within my c++ program, to the finest/lowest level possible (i.e. the smallest fraction of a second possible).
I am running my program on a Sun Solaris UNIX machine, and compiling it with g++. I am unable to get what should(?) be simple code to return a meaningful answer. example:
Code:
#include <iostream>
#include <time.h>
...
int main( int argc, char* argv[] )
{
...
time_t t1 = time(0);
//-- code to be timed goes here... should take about
//-- .001 seconds or so...
time_t t2 = time(0);
cout << "elapsed time: ."
<< double(difftime(t2,t1))
<< "." << endl;
When I run this, I invariably get
elapsed time: .0.
,even if I put a "sleep(2)" etc. in the process...
This is very frustrating. I've tried various permutations with time_t t = clock() etc. and all produce the same result.
Any help would be greatly appreciated, as I'm about at my wits end.
Thank you,
dora