Skip to content

Commit

Permalink
[WIP] Added a second json file for testing
Browse files Browse the repository at this point in the history
Addresses bwhiteley#19.

I have only done the mapping work for `vdka/JSON` and Marshal so far
  • Loading branch information
vdka committed Oct 31, 2016
1 parent bf05261 commit e49f56e
Show file tree
Hide file tree
Showing 9 changed files with 20,887 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Cartfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ github "JohnSundell/Unbox" "master"
github "SwiftyJSON/SwiftyJSON" "master"
github "Anviking/Decodable" "master"
github "Hearst-DD/ObjectMapper" ~> 2.2
github "vdka/json" ~> 0.15
github "vdka/json" ~> 0.16
github "hkellaway/Gloss" "master"
github "LoganWright/Genome" == 3.0.3
github "LoganWright/Genome" == 3.0.3
6 changes: 3 additions & 3 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github "Anviking/Decodable" "5cbd5cf2a13376e11f8c8808c437c7e8f9e45e27"
github "LoganWright/Genome" "3.0.3"
github "hkellaway/Gloss" "731d09219477c1765505473af6d5152dc968d778"
github "utahiosmac/Marshal" "5dac3b70996bbba099709528f183512ad01c7f55"
github "utahiosmac/Marshal" "ba0c55e5edfc216aae486229f6f5456ce3db4473"
github "Hearst-DD/ObjectMapper" "2.2.0"
github "SwiftyJSON/SwiftyJSON" "6a0c3a82e2b4a07723b4958146315c7928220189"
github "SwiftyJSON/SwiftyJSON" "ffbc7e4b8ee0e9ec76966007e7a7bef659aea284"
github "JohnSundell/Unbox" "0be5e80a43b247a10d4a2f08150b847c7e784967"
github "vdka/json" "0.15.0"
github "vdka/json" "0.16.1"
github "lyft/mapper" "8f5b51bee8627eaa162eb42953ef0a6521880041"
18 changes: 17 additions & 1 deletion JSONShootout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
5B69A1DE1DBEC9A400B12579 /* Decodable_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B69A1DD1DBEC9A400B12579 /* Decodable_Tests.swift */; };
5BA72ECF1DBECC0C007ADBAE /* ModelObjects.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CC97869E1CEBABE7005A5DEA /* ModelObjects.framework */; };
5BA72ED31DBECD52007ADBAE /* Decodable.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5BA72EC71DBECA48007ADBAE /* Decodable.framework */; };
5DA29ACC1DC733B100345728 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DA29ACB1DC733B100345728 /* User.swift */; };
5DA29ACE1DC733D800345728 /* User+JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DA29ACD1DC733D800345728 /* User+JSON.swift */; };
5DA29AD01DC7347100345728 /* User+Marshal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DA29ACF1DC7347100345728 /* User+Marshal.swift */; };
5DA29AD21DC7384100345728 /* Users.json in Resources */ = {isa = PBXBuildFile; fileRef = 5DA29AD11DC7384100345728 /* Users.json */; };
681299051DBFFCAB009960BE /* ObjectMapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 681299041DBFFCAB009960BE /* ObjectMapper.framework */; };
681299061DBFFCAB009960BE /* ObjectMapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 681299041DBFFCAB009960BE /* ObjectMapper.framework */; };
681299071DBFFCBC009960BE /* ObjectMapper.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 681299041DBFFCAB009960BE /* ObjectMapper.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -122,11 +126,15 @@
20A0B9561DC2584D001D8A14 /* Recording+Genome.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Recording+Genome.swift"; sourceTree = "<group>"; };
20A0B9581DC25B60001D8A14 /* Program+Genome.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Program+Genome.swift"; sourceTree = "<group>"; };
20A0B95A1DC25F03001D8A14 /* Genome_Test.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Genome_Test.swift; sourceTree = "<group>"; };
20A0B9691DC26803001D8A14 /* GenomeFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GenomeFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; };
20A0B9691DC26803001D8A14 /* GenomeFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = GenomeFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5B69A1D91DBEC84200B12579 /* Recording+Decodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Recording+Decodable.swift"; sourceTree = "<group>"; };
5B69A1DB1DBEC86A00B12579 /* Program+Decodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Program+Decodable.swift"; sourceTree = "<group>"; };
5B69A1DD1DBEC9A400B12579 /* Decodable_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Decodable_Tests.swift; sourceTree = "<group>"; };
5BA72EC71DBECA48007ADBAE /* Decodable.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Decodable.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5DA29ACB1DC733B100345728 /* User.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
5DA29ACD1DC733D800345728 /* User+JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "User+JSON.swift"; sourceTree = "<group>"; };
5DA29ACF1DC7347100345728 /* User+Marshal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "User+Marshal.swift"; sourceTree = "<group>"; };
5DA29AD11DC7384100345728 /* Users.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Users.json; sourceTree = "<group>"; };
681299041DBFFCAB009960BE /* ObjectMapper.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = ObjectMapper.framework; sourceTree = BUILT_PRODUCTS_DIR; };
681299171DC00DB1009960BE /* ObjectMapper_Test.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectMapper_Test.swift; sourceTree = "<group>"; };
681299191DC00DBB009960BE /* Program+ObjectMapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Program+ObjectMapper.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -287,6 +295,7 @@
CC3023491CF9692700B51746 /* Unbox_Tests.swift */,
AA2B38D31DC0B6D3008CECCD /* JSON_Tests.swift */,
CC5A1A4C1CEAE182007238F3 /* Large.json */,
5DA29AD11DC7384100345728 /* Users.json */,
CC5A1A181CEADE59007238F3 /* Info.plist */,
);
path = JSONShootoutTests;
Expand All @@ -299,6 +308,7 @@
CC9786A21CEBABE7005A5DEA /* Info.plist */,
CC9786BB1CEBAC14005A5DEA /* Recording.swift */,
CC9786BD1CEBAC21005A5DEA /* Program.swift */,
5DA29ACB1DC733B100345728 /* User.swift */,
CC9786BF1CEBAC6C005A5DEA /* NSDate+JSON.swift */,
71337C8A1DBEBC6B00DCA374 /* Recording+Marshal.swift */,
71337C8C1DBEBC7900DCA374 /* Recording+Mapper.swift */,
Expand All @@ -316,6 +326,8 @@
5B69A1DB1DBEC86A00B12579 /* Program+Decodable.swift */,
681299191DC00DBB009960BE /* Program+ObjectMapper.swift */,
AA2B38CD1DC0B4CC008CECCD /* Program+JSON.swift */,
5DA29ACD1DC733D800345728 /* User+JSON.swift */,
5DA29ACF1DC7347100345728 /* User+Marshal.swift */,
7C3FCD301DC1B2A100C82DEE /* Program+Gloss.swift */,
20A0B9581DC25B60001D8A14 /* Program+Genome.swift */,
);
Expand Down Expand Up @@ -451,6 +463,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5DA29AD21DC7384100345728 /* Users.json in Resources */,
CC5A1A4D1CEAE182007238F3 /* Large.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -499,14 +512,17 @@
71337C971DBEBFD000DCA374 /* Program+Unbox.swift in Sources */,
CC9786BE1CEBAC21005A5DEA /* Program.swift in Sources */,
71337C8D1DBEBC7900DCA374 /* Recording+Mapper.swift in Sources */,
5DA29ACE1DC733D800345728 /* User+JSON.swift in Sources */,
6812991B1DC00DBB009960BE /* Program+ObjectMapper.swift in Sources */,
71337C991DBEBFDC00DCA374 /* Program+SwiftyJSON.swift in Sources */,
71337C931DBEBFB400DCA374 /* Program+Marshal.swift in Sources */,
CC9786C01CEBAC6C005A5DEA /* NSDate+JSON.swift in Sources */,
5B69A1DA1DBEC84200B12579 /* Recording+Decodable.swift in Sources */,
5DA29ACC1DC733B100345728 /* User.swift in Sources */,
AA2B38D01DC0B4D2008CECCD /* Program+JSON.swift in Sources */,
7C3FCD311DC1B2A100C82DEE /* Program+Gloss.swift in Sources */,
5B69A1DC1DBEC86A00B12579 /* Program+Decodable.swift in Sources */,
5DA29AD01DC7347100345728 /* User+Marshal.swift in Sources */,
7C3FCD331DC1B2AE00C82DEE /* Recording+Gloss.swift in Sources */,
AA2B38D21DC0B57F008CECCD /* Recording+JSON.swift in Sources */,
71337C911DBEBCA300DCA374 /* Recording+SwiftyJSON.swift in Sources */,
Expand Down
38 changes: 38 additions & 0 deletions JSONShootoutTests/JSON_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,48 @@ class JSON_Tests: XCTestCase {
}
}

func testDeserialization2() {
self.measure {
do {

let json = try JSON.Parser.parse(self.usersData)

XCTAssert((json.array?.count ?? 0) > 0)
} catch {
XCTFail("Failed to parse: \(error)")
}
}
}

func testPerformance2() {
do {

let json = try JSON.Parser.parse(self.usersData)

self.measure {
do {

let users = try json.map(User.init)
XCTAssert(users.count > 100)
} catch {
XCTFail("Mapping did fail: \(error)")
}
}
} catch {
XCTFail("Failed to parse: \(error)")
}
}

private lazy var data:Data = {
let path = Bundle(for: type(of: self)).url(forResource: "Large", withExtension: "json")
let data = try! Data(contentsOf: path!)
return data
}()

private lazy var usersData:Data = {
let path = Bundle(for: type(of: self)).url(forResource: "Users", withExtension: "json")
let data = try! Data(contentsOf: path!)
return data
}()

}
55 changes: 47 additions & 8 deletions JSONShootoutTests/Marshal_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,78 @@ class Marshal_Tests: XCTestCase {
XCTAssert(d.count > 0)
}
}

func testTypedDeserialization() {
self.measure {
let json = try! JSONParser.JSONObjectWithData(self.data as Data)
XCTAssert(json.count > 0)
}
}

func testDictionaryPerformance() {
let json = try! JSONParser.JSONObjectWithData(data as Data)

self.measure {
let programs:[Program] = try! json.value(for:"ProgramList.Programs")
XCTAssert(programs.count > 1000)
}
}

func testNSDictionaryPerformance() {
let json = try! JSONSerialization.jsonObject(with: self.data as Data, options: []) as! NSDictionary

self.measure {
//for _ in 0..<10 {
//while true {
let programs:[Program] = try! json.value(for: "ProgramList.Programs")
XCTAssert(programs.count > 1000)
let programs:[Program] = try! json.value(for: "ProgramList.Programs")
XCTAssert(programs.count > 1000)
//}
}
}


func testDeserialization2() {
self.measure {
let d: NSArray = try! JSONSerialization.jsonObject(with: self.usersData as Data, options: []) as! NSArray
XCTAssert(d.count > 0)
}
}

func testTypedDeserialization2() {
self.measure {
let json = try! JSONParser.JSONArrayWithData(self.usersData as Data)
XCTAssert(json.count > 0)
}
}

func testDictionaryPerformance2() {
let json = try! JSONParser.JSONArrayWithData(self.usersData as Data)

self.measure {
let users: [User] = try! json.map(User.init(object:))
XCTAssert(users.count > 100)
}
}

/*
func testNSDictionaryPerformance2() {
let json = try! JSONSerialization.jsonObject(with: self.usersData as Data, options: []) as! NSArray

self.measure {
let users: [User] = try! json.map(User.init(object:))
XCTAssert(users.count > 1000)
}
}
*/

private lazy var data:Data = {
let path = Bundle(for: type(of: self)).url(forResource: "Large", withExtension: "json")
let data = try! Data(contentsOf: path!)
return data
}()

private lazy var usersData:Data = {
let path = Bundle(for: type(of: self)).url(forResource: "Users", withExtension: "json")
let data = try! Data(contentsOf: path!)
return data
}()
}
Loading

0 comments on commit e49f56e

Please sign in to comment.