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