Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <time.h>
- #include <stdio.h>
- #define rowcol 506
- #define repeats 200000
- int main() {
- int arr1[rowcol][rowcol];
- clock_t t_begin, t_end;
- t_begin = clock();
- for (int x = 0;x < repeats;x++) {
- for (int i = 0;i < rowcol;i++) {
- for (int j = 0; j < rowcol; j++)
- arr1[i][j] = 8;
- }
- }
- t_end = clock();
- printf("\nOperator indexing took %f milliseconds\n", ((double)t_end - (double)t_begin) / CLOCKS_PER_SEC);
- int* ptr;
- t_begin = clock();
- for (int x = 0;x < repeats;x++) {
- ptr = arr1;
- for (int i = 0;i < (rowcol*rowcol);i++) {
- *ptr = 9;
- ptr++; //increment 4 bytes. this operator does more than you would think
- }
- }
- t_end = clock();
- printf("\nPointer arithmetic took %f milliseconds\n", ((double)t_end - (double)t_begin) / CLOCKS_PER_SEC);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement