xref: /petsc/src/benchmarks/PetscGetCPUTime.c (revision fbf9dbe564678ed6eff1806adbc4c4f01b9743f4)
1 
2 #include <petsctime.h>
3 
4 int main(int argc,char **argv)
5 {
6   PetscLogDouble x,y;
7   long int       i,j,A[100000],ierr;
8 
9   PetscCall(PetscInitialize(&argc,&argv,0,0));
10   /* To take care of paging effects */
11   PetscCall(PetscGetCPUTime(&y));
12 
13   for (i=0; i<2; i++) {
14     PetscCall(PetscGetCPUTime(&x));
15 
16     /*
17        Do some work for at least 1 ms. Most CPU timers
18        cannot measure anything less than that
19      */
20 
21     for (j=0; j<20000*(i+1); j++) A[j]=i+j;
22     PetscCall(PetscGetCPUTime(&y));
23     fprintf(stdout,"%-15s : %e sec\n","PetscGetCPUTime",(y-x)/10.0);
24   }
25 
26   PetscCall(PetscFinalize());
27   return 0;
28 }
29