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