title: Swift, Calculate the execution time of a sort algorithm
body: <p>I need calculate the execution time for 2 different algorithms then determine recommend one based on execution time. So I am fairly new to algorithms and data structures in general yet alone in Swift. </p>
  
  <p>So I have done some searching and haven't found much. I did manage to find this: </p>
  
  <pre><code>func printTimeElapsedWhenRunningCode(title:String, operation:()-&gt;()) {
      let startTime = CFAbsoluteTimeGetCurrent()
      operation()
      let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
      print("Time elapsed for \(title): \(timeElapsed) s.")
  }
  </code></pre>
  
  <p>This is then what I am actually trying to test:</p>
  
  <pre><code>printTimeElapsedWhenRunningCode(title: "Merge Sort") {
      let newSort = mergeSort(sortArray)
  }
  </code></pre>
  
  <p>Now I am not sure if this is actually calculating what I am needing. Then every time I run this I always get a different time. Am I even on the right path? </p>