Hi,
longback, I had written a CPU benchmark program. From that, followign
snippet may be useful for u.
it is a bad mix of c and c++ hehe ....
void frmClockitImpl::do_clock() {
struct tms tmsstart, tmsend;
static int clktck = 0;
static double treal=0, tuser=0, tsys=0, tchlduser=0, tchldsys=0;
clock_t start, end;
int status;
static int counter=1;
int i;
if(clktck == 0) {
clktck=sysconf(_SC_CLK_TCK);
}
for(i=0;i<counter;i++) {
if((start=times(&tmsstart)) == -1) {
fprintf(stderr, "\ntimes() error 1");
return;
}
if((status=system("./musicin test.wav")) < 0) {
fprintf(stderr, "\nsystem() error 1");
return;
}
if((end=times(&tmsend)) == -1) {
fprintf(stderr, "\ntimes() error 2");
return;
}
treal = (end - start) / (double) clktck;
tuser = (tmsend.tms_utime - tmsstart.tms_utime)
/(double) clktck;
tsys = (tmsend.tms_stime - tmsstart.tms_stime)
/(double) clktck;
tchlduser = (tmsend.tms_cutime - tmsstart.tms_cutime)
/(double) clktck;
tchldsys = (tmsend.tms_cstime - tmsstart.tms_cstime)
/(double) clktck;
printf("%f, %f, %f, %f, %f\n", treal, tuser, tsys,
tchlduser, tchldsys);
this->lcdTimer->display(treal);
}
}
iti
archan
H.S.Rai wrote:
>I wish to note CPU time taken by a program. What I have done and assume is
>as below. Correct me and suggest some solution.
>
>I tried using "time ./a.out" it gave three time and think "user" is
>relevent. But I observed this "user time " vary with other load on PC.
>
>Then I tried using following arrangement:
>
>clock_t ct1, ct2;
>tms cputime1, cputime2;
>ct1 = times(&cputime1) ;
> {
> // computer code
> }
>ct2 = times(&cputime2) ;
>cout << "\n usertime " <<( cputime2.tms_utime - cputime1.tms_utime
> + cputime2.tms_cutime- cputime1.tms_cutime)/(CLOCKS_PER_SEC/10000.)
>
_______________________________________________
linux-india-help mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/linux-india-help