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: PetscCall(PetscInitialize(&argc,&argv,0,0));
10: /* To take care of paging effects */
11: PetscCall(PetscGetCPUTime(&y));
13: for (i=0; i<2; i++) {
14: PetscCall(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: PetscCall(PetscGetCPUTime(&y));
23: fprintf(stdout,"%-15s : %e sec\n","PetscGetCPUTime",(y-x)/10.0);
24: }
26: PetscCall(PetscFinalize());
27: return 0;
28: }