Date: 2022-03-04T17:40:00+00:00

Actual source code: PetscGetCPUTime.c

      2: #include <petsctime.h>

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

      9:   PetscInitialize(&argc,&argv,0,0);if (ierr) return ierr;
     10:   /* To take care of paging effects */
     11:   PetscGetCPUTime(&y);

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

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

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

     26:   PetscFinalize();
     27:   return ierr;
     28: }