Skip to content

Instantly share code, notes, and snippets.

@bsneed bsneed/Timings.txt
Last active Jan 9, 2016

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

hborders commented Nov 17, 2015

@RLovelett

This comment has been minimized.

Copy link

RLovelett commented Nov 18, 2015

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

@andreyz

This comment has been minimized.

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
You can’t perform that action at this time.