title: why is the cache-misses to instructions ratio a better indicator of cache performance compared to the cache-references to cache-misses ratio?
body: <p>I am using perf to test the code of a theoretically proven to be cache friendly algorithm.</p>
  
  <p>According to <a href="http://developers.redhat.com/blog/2014/03/10/determining-whether-an-application-has-poor-cache-performance-2/" rel="nofollow">this article</a> the cache-misses to instructions is a good indicator of cache performance.</p>
  
  <blockquote>
    <p>The ratio of cache-misses to instructions will give an indication how
    well the cache is working; the lower the ratio the better. In this
    example the ratio is 1.26% (6,605,955 cache-misses/525,543,766
    instructions). Because of the relatively large difference in cost
    between the RAM memory and cache access (100’s cycles vs &lt;20 cycles)
    even small improvements of cache miss rate can significantly improve
    performance. If the cache miss rate per instruction is over 5%,
    further investigation is required.</p>
  </blockquote>
  
  <p>However when I run perf like this:</p>
  
  <p><code>perf stat -B -e cache-references,cache-misses,instructions ./td 1.txt 2.txt</code></p>
  
  <p>Perf will print the following:</p>
  
  <pre><code>Performance counter stats for './td 1.txt 2.txt':
  
      93,497,101      cache-references                                            
      56,452,246      cache-misses              #   60.379 % of all cache refs    
   8,115,626,200      instructions             
  
     2.509309040 seconds time elapsed
  </code></pre>
  
  <p>So it focuses more on the cache-references to cache-misses ratio instead of the one suggested in the article.</p>
  
  <p>The cache-misses to cache-references ratio seems very bad, 60%, which means 60% of the time my application accesses the cache I get a cache miss. On the other hand the cache-misses to instructions ratio is only 0.6%.</p>
  
  <p>I am not sure what to get out of this. Which ratio should I aim to optimize?</p>