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.
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.
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.
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;
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;
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.
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.
ASKER
ozo,
if you resend your last comment as an answer, I can reward you the 100 points.
if you resend your last comment as an answer, I can reward you the 100 points.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
time_t start, finish;
time(&start);
code segment();
time(&finish);
printf("%f\n", difftime(finish, start));