So, we're having the following array:

Code:
int numbers[5] = { 10, 20, 30, 40, 50 };
int len = 5;
We can loop through them using two ways (or are there any more I'm not aware of?).

1:
Code:
    for (int i = 0; i < len; i++) { printf("%d\n", numbers[i]); }
2:
Code:
  int* ptr = numbers;
int len_cpy = len;
for (; len_cpy > 0; --len_cpy) { printf("%d\n", *ptr++); }

Which one will result in the fastest runtime performance? I tried to measurement them but the times are always inaccurate and very inconsistent. Let's see how I look at them with logic (with my current knowledge).

In the first case, we create a variable "i" so 1 move instruction. Then then condition check is 1 "cmp" and then 2 "jmp" instructions. Then I'm not sure how "numbers[i]" in machine language. I suppose the generated code gets a copy of the original pointer, increments it by "i" and then, de-references the pointer. So 3 instructions? And finally, we increment "i" so 1 instruction. So, we have a total of 8 instructions!

In the second case, we get a pointer to the beginning of the array and we copy the variable that holds the length of the array (as we don't want to modify the original variable that holds the length) so 2 instructions. Then we have the condition. However, it now compares against an immediate value and from what I heard, working with immediate values is faster (but how much faster?) so I suppose that even tho we have the same instructions here, it will execute faster in that case. Then, we deference the pointer and then we increment it, so 2 instructions. But in this case, we increment it by "1" which is an immediate value compared to the previous case where we increment it by the value of a variable so I suppose that incrementing will also work faster here. Finally, we decrement "len_copy" which is also 1 instruction but "subtraction" is slower than "addition" so it will be slower in that case (but how much slower?). In the end, we have 8 instructions in this case as well (but 1 less inside the loop)!

I don't know if what I'm saying is right or wrong but it's all based on my current knowledge. That's why I'm asking for help in the first place. Thank you all for your time reading this!