Advertisement
Guest User

name it

a guest
Feb 25th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <time.h>
  2. #include <stdio.h>
  3.  
  4. #define rowcol 506
  5. #define repeats 200000
  6.  
  7. int main() {
  8. int arr1[rowcol][rowcol];
  9. clock_t t_begin, t_end;
  10.  
  11. t_begin = clock();
  12. for (int x = 0;x < repeats;x++) {
  13.  
  14. for (int i = 0;i < rowcol;i++) {
  15. for (int j = 0; j < rowcol; j++)
  16. arr1[i][j] = 8;
  17. }
  18.  
  19. }
  20. t_end = clock();
  21.  
  22. printf("\nOperator indexing took %f milliseconds\n", ((double)t_end - (double)t_begin) / CLOCKS_PER_SEC);
  23.  
  24. int* ptr;
  25.  
  26.  
  27. t_begin = clock();
  28. for (int x = 0;x < repeats;x++) {
  29. ptr = arr1;
  30. for (int i = 0;i < (rowcol*rowcol);i++) {
  31. *ptr = 9;
  32. ptr++; //increment 4 bytes. this operator does more than you would think
  33. }
  34. }
  35. t_end = clock();
  36.  
  37. printf("\nPointer arithmetic took %f milliseconds\n", ((double)t_end - (double)t_begin) / CLOCKS_PER_SEC);
  38.  
  39. return 1;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement