C   71

perf

Guest on 10th June 2022 01:33:30 PM

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/times.h>
  5.  
  6.  
  7. /* Return the user time from times(2) */
  8. clock_t getTicks(void)
  9. {
  10.     struct tms mytms;
  11.  
  12.     times(&mytms);
  13.     return mytms.tms_utime;
  14. }
  15.  
  16. void bigLongLoop(void)
  17. {
  18.     int i,j;
  19.     int *arr,*p;
  20. #define SIZE 16384
  21.  
  22.     p=arr=malloc(SIZE*SIZE*sizeof(int));
  23.  
  24.     for (i=0;i<SIZE;i++) {
  25.     for (j=0;j<SIZE;j++) {
  26.         *p++=i+j;
  27.     }}
  28.  
  29.     free(arr);
  30.  
  31. }
  32.  
  33. int main(int argc, char *argv[])
  34. {
  35.     clock_t tStart,tEnd;
  36.  
  37.     tStart = getTicks();
  38.     bigLongLoop();
  39.     tEnd = getTicks();
  40.  
  41.     printf("start=%lu end=%lu diff=%lu\n",
  42.             tStart,tEnd,tEnd-tStart);
  43.  
  44.  
  45.     return 0;
  46. }

Raw Paste


Login or Register to edit or fork this paste. It's free.