Link to home
Start Free TrialLog in
Avatar of tclot
tclot

asked on

clock tics-based code profiling in C with SCO3.0, How?

I want to be able to measure execution performance of some
code in SCO3.0 (Unix Ver V, rel 3.2). I want to do it in C if possible. I want to get measure before code segment, get
measure after segment, take the difference, and convert to
seconds (or fraction of). I don't necessarily need measure
in tics, as long as result is in subseconds. Ideas would be
greatly appreciated.
Avatar of ozo
ozo
Flag of United States of America image

#include <time.h>
time_t  start, finish;
time(&start);

code segment();

time(&finish);
printf("%f\n", difftime(finish, start));
Avatar of tclot
tclot

ASKER

ozo,
thanks for the response. When I do what you suggest, start and finish are in seconds, not tics. So when I take the difference, its always zero unless the code segment takes longer than 1 second. If you have any other ideas would be greatly appreciated.
You might try

for( i=0; i<1000; i++ ){ code segment(); }

or

#include <sys/types.h>
#include <sys/times.h>
struct tms buffer;
times (&buffer);
ticks=buffer.tms_utime;

or

#include  <sys/types.h>
#include  <sys/timeb.h>
#include  <time.h>
struct timeb tp[1];
ftime (tp);
ticks= tp->millitm;

Avatar of tclot

ASKER

ozo,
Thanks! The third option worked (using struct timeb). I want to award you the points, but not sure how to since you added a comment instead of an answer. I'll figure it out... Thanks again.
Avatar of tclot

ASKER

ozo,
if you resend your last comment as an answer, I can reward you the 100 points.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial