Actual source code: PetscGetCPUTime.c

petsc-3.7.3 2016-08-01
Report Typos and Errors
  2: #include <petsctime.h>

  6: int main(int argc,char **argv)
  7: {
  8:   PetscLogDouble x,y;
  9:   long int       i,j,A[100000],ierr;

 11:   PetscInitialize(&argc,&argv,0,0);
 12:   /* To take care of paging effects */
 13:   PetscGetCPUTime(&y);

 15:   for (i=0; i<2; i++) {
 16:     PetscGetCPUTime(&x);

 18:     /*
 19:        Do some work for at least 1 ms. Most CPU timers
 20:        cannot measure anything less than that
 21:      */

 23:     for (j=0; j<20000*(i+1); j++) A[j]=i+j;
 24:     PetscGetCPUTime(&y);
 25:     fprintf(stdout,"%-15s : %e sec\n","PetscGetCPUTime",(y-x)/10.0);
 26:   }

 28:   PetscFinalize();
 29:   return(0);
 30: }