I'm wondering why my function is taking so much time to build. Longest time for me is 206.1ms, this is over 3 minutes !
187721.1ms InspectionViewController.swift:423:17 @IBAction @objc func btnSaveTouch(_ sender: Any)
I was looking for some optimizations, but can't find any reasonable reason why my function is so slow.
I'm using Alamofire here, and couple of fields (text fields, text views, and 2 x switches)
code looks like that:
@IBAction func btnSaveTouch(_ sender: Any) {
var two_storeys = ""
var legal_height_downstairs = ""
if s_two_storeys.isOn {
two_storeys = "Yes"
} else {
two_storeys = "No"
}
if s_legal_height_downstairs.isOn {
legal_height_downstairs = "Yes"
} else {
legal_height_downstairs = "No"
}
let parameters : Parameters = [
"inspection_date" : tf_inspection_date.text!,
"property_type" : tf_property_type.text!,
"beds" : tf_beds.text!,
"baths" : tf_baths.text!,
"cars" : tf_cars.text!,
"our_price_min" : tf_our_price_min.text!,
"our_price_max" : tf_our_price_max.text!,
"max_rent" : tf_rent_max.text!,
"min_rent" : tf_rent_min.text!,
"upfront_max": tf_upfront_max.text!,
"character": tf_character.text!,
"character_years": tf_character_years.text!,
"character_uers": tf_character_year.text!,
"build_construction": tf_build_construction.text!,
"roof_material": tv_roof_material.text!,
"house_on": tf_house_on.text!,
"two_storeys": two_storeys,
"legal_height_downstairs": legal_height_downstairs,
"legal_height_downstairs_value" : tv_legal_height_downstairs_value.text!
]
Alamofire.request(saveUrl, method: .post, parameters: parameters).responseJSON { response in
_ = handleError(response: response)
}
}
so Eric Aya was right. Now compile time for this function is 19.9ms. Working code below.
var paramaters : Parameters = [:]
paramaters["inspection_date"] = tf_inspection_date.text!
paramaters["property_type"] = tf_property_type.text!
paramaters["beds"] = tf_beds.text!
paramaters["baths"] = tf_baths.text!
paramaters["cars"] = tf_cars.text!
paramaters["our_price_min"] = tf_our_price_min.text!
paramaters["our_price_max"] = tf_our_price_max.text!
paramaters["max_rent"] = tf_rent_max.text!
paramaters["min_rent"] = tf_rent_min.text!
paramaters["upfront_max"] = tf_upfront_max.text!
paramaters["character"] = tf_character.text!
paramaters["character_years"] = tf_character_years.text!
paramaters["character_uers"] = tf_character_year.text!
paramaters["build_construction"] = tf_build_construction.text!
paramaters["roof_material"] = tv_roof_material.text!
paramaters["house_on"] = tf_house_on.text!
paramaters["two_storeys"] = two_storeys
paramaters["legal_height_downstairs"] = legal_height_downstairs
paramaters["legal_height_downstairs_value"] = tv_legal_height_downstairs_value.text!
Answering Jeremy's question - Yes, got pretty simple code: