title: Comparing SQL query performance
body: <p>I'm redesigning some of my database tables. I have 2 keys in the same table that can be used to query data and I'd like to compare the difference in performance between them. Querying with the newer key is slower so I'd like to have a method which I can run after making schema changes to re-assess query performance.</p>
  
  <p>I know about Execution plans in MS SQL Server and <code>SET STATISTICS IO, TIME ON</code>. However, I'd like to have a very simple absolute time taken which gives me realistic results. Considering each query takes about 4s, I have to run the same query multiple times consecutively in a loop. I currently have:</p>
  
  <pre><code>USE [MyDb]
  
  CHECKPOINT
  DBCC FREESYSTEMCACHE('ALL')
  
  &lt;query&gt;
  </code></pre>
  
  <p>If I ran the above in a loop via powershel <code>sqlcmd</code>, would the clearing of the cache be enough to clear effects of running the same query just before the current run?</p>