title: How to test generic performance with whole module optimization
body: <p>In WWDC 2015 Session 409 near the 18 minute mark. The discussion at hand leads me to believe that generics can be optimized through Generic Specialization by enabling whole module optimization mode. Unfortunately my tests, which I'm not confident in, revealed nothing useful.</p>
  
  <p>I ran some very simple tests between the following two methods to see if the performance was similar:</p>
  
  <pre><code>func genericMax&lt;T : Comparable&gt;(x:T, y:T) -&gt; T {
      return y &gt; x ? y : x
  }
  
  func intMax(x:Int, y:Int) -&gt; Int {
      return y &gt; x ? y : x
  }
  </code></pre>
  
  <p><strong>Simple XCTest:</strong></p>
  
  <pre><code>func testPerformanceExample() {
  
      self.measureBlock {
  
          let x: Int = Int(arc4random_uniform(9999))
          let y: Int = Int(arc4random_uniform(9999))
  
          for _ in 0...1000000 {
              // let _ = genericMax(x, y: y)
              let _ = intMax(x, y: y)
          }
      }
  }
  </code></pre>
  
  <h2>What happened</h2>
  
  <p>Without optimization the following tests were reasonably different:</p>
  
  <ul>
  <li>genericMax: 0.018 sec</li>
  <li>intMax: 0.005 sec</li>
  </ul>
  
  <p>However with Whole Module Optimization the following tests weren't similar:</p>
  
  <ul>
  <li>genericMax: 0.014 sec</li>
  <li>intMax: 0.004 sec</li>
  </ul>
  
  <h2>What I Expected</h2>
  
  <p>With whole module optimization enabled I expected similar times between the two methods calls. This leads me to believe that my test is flawed.</p>
  
  <h2>Question</h2>
  
  <p>Assuming my tests are flawed / poor. How could I better measure how Whole Module Optimization mode optimizes generics through Generic Specialization?</p>