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