Skip to content

Instantly share code, notes, and snippets.

@bsneed
Last active January 9, 2016 17:29
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsneed/c55e71773c3c8e712ea5 to your computer and use it in GitHub Desktop.
Save bsneed/c55e71773c3c8e712ea5 to your computer and use it in GitHub Desktop.
Performance Comparison of Swift JSON->Model frameworks.
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)
}
}
}
@hborders
Copy link

@RLovelett
Copy link

Could you provide a link to Coconut? Not sure what that framework is.

@andreyz
Copy link

andreyz commented Dec 14, 2015

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