xref: /petsc/src/benchmarks/PetscGetCPUTime.c (revision e2c586eb4ae28aada0cde77bf70ec9ba56e8fcee)
1 
2 #include <petsctime.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   ierr = PetscInitialize(&argc,&argv,0,0);if (ierr) return ierr;
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++) A[j]=i+j;
24     ierr = PetscGetCPUTime(&y);CHKERRQ(ierr);
25     fprintf(stdout,"%-15s : %e sec\n","PetscGetCPUTime",(y-x)/10.0);
26   }
27 
28   ierr = PetscFinalize();
29   return ierr;
30 }
31