Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Added a second json file for testing #20

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -7,3 +7,4 @@ github "Hearst-DD/ObjectMapper" ~> 2.2
github "vdka/json" ~> 0.16
github "hkellaway/Gloss" "master"
github "LoganWright/Genome" == 3.0.3
github "postmates/PMJSON" "master"
11 changes: 6 additions & 5 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
github "Anviking/Decodable" "5cbd5cf2a13376e11f8c8808c437c7e8f9e45e27"
github "Anviking/Decodable" "0a59e61d2522dc2f42f3b9f636dcce3869651c92"
github "LoganWright/Genome" "3.0.3"
github "hkellaway/Gloss" "731d09219477c1765505473af6d5152dc968d778"
github "utahiosmac/Marshal" "ba0c55e5edfc216aae486229f6f5456ce3db4473"
github "Hearst-DD/ObjectMapper" "2.2.0"
github "SwiftyJSON/SwiftyJSON" "ffbc7e4b8ee0e9ec76966007e7a7bef659aea284"
github "JohnSundell/Unbox" "0be5e80a43b247a10d4a2f08150b847c7e784967"
github "vdka/json" "0.16.1"
github "Hearst-DD/ObjectMapper" "2.2.1"
github "postmates/PMJSON" "2857cd48632974c0e3b79f9c05d3a07cfd6f637b"
github "SwiftyJSON/SwiftyJSON" "1dc2ce0f913b27380cd5b803af8aa853745b9608"
github "JohnSundell/Unbox" "ac69e55c85a7d7e155b06c001bcbea26c19f3375"
github "vdka/json" "0.16.2"
github "lyft/mapper" "8f5b51bee8627eaa162eb42953ef0a6521880041"
20 changes: 18 additions & 2 deletions JSONShootout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -14,6 +14,10 @@
20A0B9591DC25B60001D8A14 /* Program+Genome.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20A0B9581DC25B60001D8A14 /* Program+Genome.swift */; };
20A0B95B1DC25F03001D8A14 /* Genome_Test.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20A0B95A1DC25F03001D8A14 /* Genome_Test.swift */; };
20A0B96B1DC26810001D8A14 /* GenomeFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 20A0B9691DC26803001D8A14 /* GenomeFoundation.framework */; };
20BB48341DD223FC00B72AE5 /* User+Genome.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20BB48331DD223FC00B72AE5 /* User+Genome.swift */; };
20BB48361DD232D100B72AE5 /* User+Gloss.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20BB48351DD232D100B72AE5 /* User+Gloss.swift */; };
20BB48381DD2440F00B72AE5 /* User+Mapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20BB48371DD2440F00B72AE5 /* User+Mapper.swift */; };
20BB483A1DD247C200B72AE5 /* User+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20BB48391DD247C200B72AE5 /* User+Decodable.swift */; };
5B69A1DA1DBEC84200B12579 /* Recording+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B69A1D91DBEC84200B12579 /* Recording+Decodable.swift */; };
5B69A1DC1DBEC86A00B12579 /* Program+Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B69A1DB1DBEC86A00B12579 /* Program+Decodable.swift */; };
5B69A1DE1DBEC9A400B12579 /* Decodable_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B69A1DD1DBEC9A400B12579 /* Decodable_Tests.swift */; };
@@ -132,6 +136,10 @@
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; path = GenomeFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; };
20BB48331DD223FC00B72AE5 /* User+Genome.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "User+Genome.swift"; sourceTree = "<group>"; };
20BB48351DD232D100B72AE5 /* User+Gloss.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "User+Gloss.swift"; sourceTree = "<group>"; };
20BB48371DD2440F00B72AE5 /* User+Mapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "User+Mapper.swift"; sourceTree = "<group>"; };
20BB48391DD247C200B72AE5 /* User+Decodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "User+Decodable.swift"; sourceTree = "<group>"; };
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>"; };
@@ -342,11 +350,15 @@
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 */,
9E9BF9CD1DCD126D00548161 /* Program+PMJSON.swift */,
5DA29ACD1DC733D800345728 /* User+JSON.swift */,
5DA29ACF1DC7347100345728 /* User+Marshal.swift */,
20BB48331DD223FC00B72AE5 /* User+Genome.swift */,
20BB48351DD232D100B72AE5 /* User+Gloss.swift */,
20BB48371DD2440F00B72AE5 /* User+Mapper.swift */,
20BB48391DD247C200B72AE5 /* User+Decodable.swift */,
);
path = ModelObjects;
sourceTree = "<group>";
@@ -527,9 +539,11 @@
files = (
71337C8F1DBEBC8600DCA374 /* Recording+Unbox.swift in Sources */,
6812991C1DC00DBB009960BE /* Recording+ObjectMapper.swift in Sources */,
20BB48341DD223FC00B72AE5 /* User+Genome.swift in Sources */,
71337C971DBEBFD000DCA374 /* Program+Unbox.swift in Sources */,
CC9786BE1CEBAC21005A5DEA /* Program.swift in Sources */,
71337C8D1DBEBC7900DCA374 /* Recording+Mapper.swift in Sources */,
20BB483A1DD247C200B72AE5 /* User+Decodable.swift in Sources */,
5DA29ACE1DC733D800345728 /* User+JSON.swift in Sources */,
6812991B1DC00DBB009960BE /* Program+ObjectMapper.swift in Sources */,
9E9BF9D01DCD307200548161 /* Recording+PMJSON.swift in Sources */,
@@ -547,8 +561,10 @@
AA2B38D21DC0B57F008CECCD /* Recording+JSON.swift in Sources */,
71337C911DBEBCA300DCA374 /* Recording+SwiftyJSON.swift in Sources */,
20A0B9571DC2584D001D8A14 /* Recording+Genome.swift in Sources */,
20BB48381DD2440F00B72AE5 /* User+Mapper.swift in Sources */,
71337C951DBEBFC300DCA374 /* Program+Mapper.swift in Sources */,
71337C8B1DBEBC6B00DCA374 /* Recording+Marshal.swift in Sources */,
20BB48361DD232D100B72AE5 /* User+Gloss.swift in Sources */,
20A0B9591DC25B60001D8A14 /* Program+Genome.swift in Sources */,
CC9786BC1CEBAC14005A5DEA /* Recording.swift in Sources */,
);
20 changes: 13 additions & 7 deletions JSONShootoutTests/Decodable_Tests.swift
Original file line number Diff line number Diff line change
@@ -11,13 +11,6 @@ import ModelObjects
import Decodable

class Decodable_Tests: XCTestCase {

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

func testPerformance() {
let dict = try! JSONSerialization.jsonObject(with: self.data as Data, options: []) as! NSDictionary
@@ -28,11 +21,24 @@ class Decodable_Tests: XCTestCase {
}
}

func testPerformance2() {
let dict: NSArray = try! JSONSerialization.jsonObject(with: self.usersData as Data, options: []) as! NSArray
self.measure {
let users: [User] = try! [User].decode(dict)
XCTAssert(users.count > 100)
}
}

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
}()

}
15 changes: 14 additions & 1 deletion JSONShootoutTests/Genome_Test.swift
Original file line number Diff line number Diff line change
@@ -22,7 +22,14 @@ class Genome_Test: XCTestCase {
}
let programs: [Program] = try! [Program](node: datas)
XCTAssert(programs.count > 1000)

}
}

func testPerformance2() {
let json = try! self.usersData.makeNode()
self.measure {
let users: [User] = try! [User](node: json)
XCTAssert(users.count > 100)
}
}

@@ -32,4 +39,10 @@ class Genome_Test: XCTestCase {
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
}()

}
16 changes: 15 additions & 1 deletion JSONShootoutTests/Gloss_Tests.swift
Original file line number Diff line number Diff line change
@@ -22,10 +22,24 @@ class Gloss_Tests: XCTestCase {
}
}

func testPerformance2() {
let dict: [[String: Any]] = try! JSONSerialization.jsonObject(with: self.usersData, options: []) as! [[String: Any]]

self.measure {
let users: [User] = [User].from(jsonArray: dict) ?? []
XCTAssert(users.count > 100)
}
}

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
}()
}
21 changes: 14 additions & 7 deletions JSONShootoutTests/Mapper_Tests.swift
Original file line number Diff line number Diff line change
@@ -12,13 +12,6 @@ import Mapper

class Mapper_Tests: XCTestCase {

func testDeserialization() {
self.measure {
let d:NSDictionary = try! JSONSerialization.jsonObject(with:self.data, options: []) as! NSDictionary
XCTAssert(d.count > 0)
}
}

func testPerformance() {

let dict = try! JSONSerialization.jsonObject(with: self.data as Data, options: []) as! NSDictionary
@@ -30,10 +23,24 @@ class Mapper_Tests: XCTestCase {
}
}

func testPerformance2() {
let dict: NSArray = try! JSONSerialization.jsonObject(with: self.usersData as Data, options: []) as! NSArray
self.measure {
let users: [User] = User.from(dict)!
XCTAssert(users.count > 100)
}
}

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
}()

}
14 changes: 14 additions & 0 deletions ModelObjects/Program+Mapper.swift
Original file line number Diff line number Diff line change
@@ -4,3 +4,17 @@
//

import Mapper

extension Program: Mappable {
public init(map: Mapper) throws {
title = try map.from("Title")
chanId = try map.from("Channel.ChanId")
// startTime = try map.from("StartTime")
// endTime = try map.from("EndTime")
description = try map.from("Description")
subtitle = try map.from("SubTitle")
recording = try map.from("Recording")
season = (try map.from("Season") as String?).flatMap({Int($0)})
episode = (try map.from("Episode") as String?).flatMap({Int($0)})
}
}
15 changes: 0 additions & 15 deletions ModelObjects/Recording+Mapper.swift
Original file line number Diff line number Diff line change
@@ -15,18 +15,3 @@ extension Recording: Mappable {
recGroup = map.optionalFrom("RecGroup") ?? .Unknown
}
}

extension Program: Mappable {
public init(map: Mapper) throws {
title = try map.from("Title")
chanId = try map.from("Channel.ChanId")
// startTime = try map.from("StartTime")
// endTime = try map.from("EndTime")
description = try map.from("Description")
subtitle = try map.from("SubTitle")
recording = try map.from("Recording")
season = (try map.from("Season") as String?).flatMap({Int($0)})
episode = (try map.from("Episode") as String?).flatMap({Int($0)})
}
}

50 changes: 50 additions & 0 deletions ModelObjects/User+Decodable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// User+Decodable.swift
// JSONShootout
//
// Created by Wane Wang on 11/9/16.
// Copyright © 2016 SwiftBit. All rights reserved.
//

import Decodable

extension User.Friend: Decodable {

public static func decode(_ json: Any) throws -> User.Friend {
return try User.Friend(
id: json => "id",
name: json => "name"
)
}
}

extension User: Decodable {

public static func decode(_ json: Any) throws -> User {
return try User(
id : json => "_id",
index : json => "index",
guid : json => "guid",
isActive : json => "isActive",
balance : json => "balance",
picture : json => "picture",
age : json => "age",
eyeColor : User.Color(rawValue: json => "eyeColor") ?? .red,
name : json => "name",
gender : User.Gender(rawValue: json => "gender") ?? .male,
company : json => "company",
email : json => "email",
phone : json => "phone",
address : json => "address",
about : json => "about",
registered : json => "registered",
latitude : json => "latitude",
longitude : json => "longitude",
tags : json => "tags",
friends : json => "friends",
greeting : json => "greeting",
favoriteFruit : json => "favoriteFruit"
)
}

}
51 changes: 51 additions & 0 deletions ModelObjects/User+Genome.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// User+Genome.swift
// JSONShootout
//
// Created by Wane Wang on 11/8/16.
// Copyright © 2016 SwiftBit. All rights reserved.
//

import Genome

extension User.Friend: MappableObject {
public init(map: Map) throws {
self.id = try map.extract("id")
self.name = try map.extract("name")
}

public func sequence(_ map: Map) throws { }
}

extension User: MappableObject {

public init(map: Map) throws {
self.id = try map.extract("_id")
self.index = try map.extract("index")
self.guid = try map.extract("guid")
self.isActive = try map.extract("isActive")
self.balance = try map.extract("balance")
self.picture = try map.extract("picture")
self.age = try map.extract("age")
self.eyeColor = try map.extract("eyeColor") { User.Color(rawValue: $0) ?? .red }
self.name = try map.extract("name")
self.gender = try map.extract("gender") { User.Gender(rawValue: $0) ?? .male }
self.company = try map.extract("company")
self.email = try map.extract("email")
self.phone = try map.extract("phone")
self.address = try map.extract("address")
self.about = try map.extract("about")
self.registered = try map.extract("registered")
self.latitude = try map.extract("latitude")
self.longitude = try map.extract("longitude")
self.tags = try map.extract("tags")
self.friends = try map.extract("friends")
self.greeting = try map.extract("greeting")
self.favoriteFruit = try map.extract("favoriteFruit")
}

public func sequence(_ map: Map) throws {

}

}
Loading