#include <stdio.h> #include <sys/types.h> #include <sys/time.h> #define N 80 #define NPROVE 5 double m1[N][N]; double m2[N][N]; long deltausecs(struct timeval last, struct timeval first); long guess_clock_overhead(); int main(int argc,char **argv) { int p,q,z; long overhusec; long deltaus; struct timeval before,after; printf("clock overhead: %ld\n",overhusec = guess_clock_overhead()); for (z=0 ; z<NPROVE ; z++) { (void) gettimeofday(&before, (struct timezone *) 0); for (p=0 ; p<N ; p++) for (q=0 ; q<N ; q++) { m1[p][q] = p; m2[p][q] = 1; } (void) gettimeofday(&after, (struct timezone *) 0); deltaus = deltausecs(after,before); printf("Elapsed Time: %ld microsec \n",deltaus-overhusec); } return 0; } /* elapsed time, assuming midnight not bracketed */ long deltausecs(struct timeval last,struct timeval first) { return (last.tv_sec - first.tv_sec) * 1000000L + last.tv_usec - first.tv_usec; } /* clock overhead estimate */ long guess_clock_overhead() { register int i; long sumt,cnt; long volatile deltausec; struct timeval before,after; sumt = cnt = 0L; /* cache clock code */ (void) gettimeofday(&before, (struct timezone *) 0); (void) gettimeofday(&after , (struct timezone *) 0); deltausec = deltausecs(after,before); for (i = 0 ; i < 100 ; ++i ) { (void) gettimeofday(&before, (struct timezone *) 0); (void) gettimeofday(&after , (struct timezone *) 0); deltausec = deltausecs(after,before); if (deltausec < 100) { sumt += deltausec; cnt++; } } printf("sumt %ld cnt %ld\n",sumt,cnt); if (!cnt) /* horrible special case */ return 20L; else return sumt/cnt; } -- Users.AntonioValletta - 14 Nov 2001
![]() |
![]() |
Questo sito usa cookies, usandolo ne accettate la presenza. (CookiePolicy)
Torna al Dipartimento di Informatica ![]() |
|
![]() |
![]() |