title: Performance difference in accessing an item in an array vs pointer reference?
body: <p>I'm fresh to C - used to scripting languages like, PHP, JS, Ruby etc. Got a query in regard to performance. I know one should not micro optimize too early - however, I'm writing a Ruby C Extension for Google SketchUp where I'm doing lots of 3D calculations so performance is a concern. (And this question is also for learning how C works.)</p>
  
  <p>Often many iterations is done to process all the 3D data so I'm trying to work out what might be faster.</p>
  
  <p>I'm wondering if accessing an array entry many times is faster if I make a pointer reference to that array entry? What would common practice be?</p>
  
  <pre><code>struct FooBar arr[10];
  int i;
  for ( i = 0; i &lt; 10; i++ ) {
    arr[i].foo = 10;
    arr[i].bar = 20;
    arr[i].biz = 30;
    arr[i].baz = 40;
  }
  </code></pre>
  
  <p>Would this be faster or slower? Why?</p>
  
  <pre><code>struct FooBar arr[10], *item;
  int i;
  for ( i = 0; i &lt; 10; i++ ) {
    item = &amp;arr[i];
    item-&gt;foo = 10;
    item-&gt;bar = 20;
    item-&gt;biz = 30;
    item-&gt;baz = 40;
  }
  </code></pre>
  
  <p>I looked around and found discussions about variables vs pointers - where it was generally said that pointers required extra steps since it had to look up the address, then the value - but in general there wasn't a bit hit.</p>
  
  <p>But what I was wondering was if accessing an array entry in C has much of a performance hit? In Ruby it is faster to make a reference to the entry if you need to access it many time - but that's Ruby...</p>