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