Last active
January 9, 2016 17:29
-
-
Save bsneed/c55e71773c3c8e712ea5 to your computer and use it in GitHub Desktop.
Performance Comparison of Swift JSON->Model frameworks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Time to decode 10,000 Person struct's from JSON: | |
Argo (Simple): 8.563 seconds | |
measureBlock { | |
let _ : [Person]? = decode(data) | |
} | |
Argo (Decomp'd): 3.344 | |
measureBlock { | |
let json: Argo.JSON = JSON.parse(data) | |
let decoded = JSON.decode(json) | |
let _ = decoded.map { Person.decode($0)} | |
} | |
Genome: 1.458 seconds | |
measureBlock { | |
do { | |
_ = try [Person].mappedInstance(data as! [Genome.JSON]) | |
} catch let error { | |
XCTFail("\(error)") | |
} | |
} | |
Decodable: 0.460 seconds | |
measureBlock { | |
do { | |
_ = try [Person].decode(data) | |
} catch let error { | |
XCTFail("\(error)") | |
} | |
} | |
Coconut: 0.216 seconds | |
measureBlock { | |
do { | |
_ = try [Person].decode(json) | |
} catch let error { | |
XCTFail("\(error)") | |
} | |
} | |
By Hand: 0.118 seconds | |
measureBlock { | |
if let array = data as? [AnyObject] { | |
let _ : [Person?] = array.map { object in | |
guard let dic = object as? NSDictionary else { return nil} | |
let firstName = dic["firstName"] as? String ?? "" | |
let secondName = dic["secondName"] as? String | |
let age = dic["age"] as? Int ?? 0 | |
let descript = dic["description"] as? String ?? "" | |
var hoobies = [String]() | |
if let h = dic["hobbies"] as? [String] { | |
hoobies = h | |
} | |
return Person(firstName: firstName, | |
secondName: secondName, | |
age: age, | |
hoobies: hoobies, | |
description: descript) | |
} | |
} | |
} |
Could you provide a link to Coconut? Not sure what that framework is.
Curios as to how would https://github.com/JohnSundell/Unbox fare in comparison
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add ObjectMapper?