Actual source code: PetscGetCPUTime.c

  1: #include <petsctime.h>

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

  8:   PetscCall(PetscInitialize(&argc,&argv,0,0));
  9:   /* To take care of paging effects */
 10:   PetscCall(PetscGetCPUTime(&y));

 12:   for (i=0; i<2; i++) {
 13:     PetscCall(PetscGetCPUTime(&x));

 15:     /*
 16:        Do some work for at least 1 ms. Most CPU timers
 17:        cannot measure anything less than that
 18:      */

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

 25:   PetscCall(PetscFinalize());
 26:   return 0;
 27: }