title: Measuring Time Accurately in Swift for Comparison Across Devices
body: <p>I need to be able to record reaction time, from when the screen loads or the question label refreshes until the user taps a number button. I'm not finding documentation from Apple on this to be very helpful. <code>NSDate</code> is not accurate enough, I need to measure to milliseconds at least. <code>mach_absolute_time</code> seems to be favored by game designers because it is internally consistent, but it won't work for this application because I need to compare data across devices, and <code>mach_absolute_time</code> is CPU dependent time. <a href="https://developer.apple.com/library/mac/qa/qa1398/_index.html" rel="nofollow">This Apple Dev Q&amp;A</a> suggests using <code>NanosecondsToAbsolute</code> and <code>DurationToAbsolute</code> but it's in obj-c and I can't find a swift equivalent documentation.</p>
  
  <p>Is there a swift version of <code>NanosecondsToAbsolute</code> and <code>DurationToAbsolute</code> that I'm just not finding? Some other way to do this consistently?</p>
  
  <p>Here's the code I'm trying to add the times to:</p>
  
  <pre><code>class EmotionQuestionsViewController: UIViewController{
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
  //mark "startTime" when view loads
      }
  
      @IBOutlet var questionLabel: UILabel!
      var timeResultsStack = [String]()
  
      var questionsStack = ["HAPPY", "ANXIOUS"]
      var questionResultsStack = [String]()
      var questionStackArrayIndex = 1
  
      @IBAction func RecordValueFromNumericalScaleOneToSeven(sender: UIButton) {
  
  //mark durration time as currentTime - startTime, append to timeResultsStack
  
          let value = sender.currentTitle!
          questionResultsStack.append(value)
  
          if questionResultsStack.count &lt; questionsStack.count{
              self.questionLabel.text = "how \(questionsStack[questionStackArrayIndex]) are you right now?"
  
  //mark startTime when label is changed
  
              self.questionStackArrayIndex++
  
          }
          else{
              self.performSegueWithIdentifier("showResults", sender: nil)
  
          }
      }
  </code></pre>