title: Checking response Time of API in iOS using Swift 3?
body: <p>I know to test the response time of API is basically done by Server or Backend side, but as i am working for one application, i need to check api response time from iOS End also.</p>
  
  <p>How can i do this ? i read few links where it says to do this using timer start and timer end and then find the response time by <strong>endTime - startTime</strong>  but this seems not handy.</p>
  
  <p>I want to use Xcode (even if XCTest is there).</p>
  
  <p>Here is my one of API ( i wrote all web service consume method in separate class in ApiManager class  ) :</p>
  
  <p><strong>LoginVC</strong> :</p>
  
  <pre><code>//Call Webservice
  let apiManager      = ApiManager()
  apiManager.delegate = self
  apiManager.getUserInfoAPI()
  </code></pre>
  
  <p><strong>ApiManager</strong> : </p>
  
  <pre><code>func getUserInfoAPI()  {
      //Header
      let headers =       [
          "Accept"        : "application/json",
          "Content-Type"  : "application/json",
      ]
  
      //Call Web API using Alamofire library
      AlamoFireSharedManagerInit()
      Alamofire.request(HCConstants.URL, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: headers).responseJSON {  response in
  
          do{
              //Checking For Error
              if let error = response.result.error {
                  //Stop AcitivityIndicator
                  self.hideHud()
                  //Call failure delegate method
                  //print(error)
                    self.delegate?.APIFailureResponse(HCConstants.EXCEPTION_MESSAGES.SERVICE_FAILURE)
                  return
              }
  
              //Store Response
              let responseValue = try JSONSerialization.jsonObject(with: response.data!, options: JSONSerialization.ReadingOptions()) as! Dictionary&lt;String, AnyObject&gt;
              print(responseValue)
  
              //Save token 
              if let mEmail = responseValue[HCConstants.Email] as? String {
                  UserDefaults.standard.setValue(mEmail, forKey: HCConstants. mEmail)
              }
  
              //Stop AcitivityIndicator
              self.hideHud()
              //Check Success Flag
              if let _ = responseValue["info"] as? String {
                  //Call success delegate method
                  self.delegate?.apiSuccessResponse(responseValue)
              }
              else {
                  //Failure message
                  self.delegate?.APIFailureResponse(responseValue["message"] as? String ?? HCConstants.EXCEPTION_MESSAGES.SERVICE_FAILURE)
              }
  
          } catch {print("Exception is there "}
      }
  }
  </code></pre>