diff --git a/Package.resolved b/Package.resolved index 68ddb3c..3905719 100644 --- a/Package.resolved +++ b/Package.resolved @@ -9,24 +9,6 @@ "version" : "0.1.6" } }, - { - "identity" : "swift-argument-parser", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-argument-parser", - "state" : { - "revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531", - "version" : "1.2.3" - } - }, - { - "identity" : "swift-benchmark", - "kind" : "remoteSourceControl", - "location" : "https://github.com/google/swift-benchmark.git", - "state" : { - "revision" : "8163295f6fe82356b0bcf8e1ab991645de17d096", - "version" : "0.1.2" - } - }, { "identity" : "swift-syntax", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 36cee71..ccdc0fa 100644 --- a/Package.swift +++ b/Package.swift @@ -32,10 +32,6 @@ let package = Package( url: "https://github.com/apple/swift-syntax.git", from: "509.0.0" ), - .package( - url: "https://github.com/google/swift-benchmark.git", - from: "0.1.2" - ), ], targets: [ .macro( @@ -75,15 +71,5 @@ let package = Package( ), ] ), - .executableTarget( - name: "ananda-benchmark", - dependencies: [ - "Ananda", - .product( - name: "Benchmark", - package: "swift-benchmark" - ), - ] - ), ] ) diff --git a/README.md b/README.md index 411b33e..1c070a9 100644 --- a/README.md +++ b/README.md @@ -124,17 +124,7 @@ Simple and clean, right? ## Benchmark -Run `swift run -c release ananda-benchmark` with Xcode 15 RC. - -``` -name time std iterations -------------------------------------------------------------- -Codable decoding 18417.000 ns ± 7.15 % 74022 -Ananda decoding 2667.000 ns ± 9.73 % 524924 -Ananda decoding with Macro 2667.000 ns ± 7.48 % 521661 -``` - -As you can see, Ananda decoding is way faster than Codable decoding. +See [AnandaBenchmark](https://github.com/nixzhu/AnandaBenchmark). ## Tool diff --git a/Sources/ananda-benchmark/main.swift b/Sources/ananda-benchmark/main.swift deleted file mode 100644 index d0ee02d..0000000 --- a/Sources/ananda-benchmark/main.swift +++ /dev/null @@ -1,116 +0,0 @@ -import Foundation -import Ananda -import Benchmark - -let jsonData = """ - { - "name": "Ducky Model Editor", - "introduction": "I'm Ducky, a document-based app that helps you infer models from JSON.", - "supported_outputs": [ - "JOSN Schema", - "Swift", - "Kotlin", - "Dart", - "Go", - "Proto" - ], - "developer": { - "user_id": 42, - "username": "nixzhu", - "email": "zhuhongxu@gmail.com", - "website_url": "https://nixzhu.dev" - } - } - """.data(using: .utf8)! - -benchmark("Codable decoding") { - struct IndieApp: Decodable { - struct Developer: Decodable { - let userID: Int - let username: String - let email: String - let websiteURL: URL - - private enum CodingKeys: String, CodingKey { - case userID = "user_id" - case username - case email - case websiteURL = "website_url" - } - } - - let name: String - let introduction: String - let supportedOutputs: [String] - let developer: Developer - - private enum CodingKeys: String, CodingKey { - case name - case introduction - case supportedOutputs = "supported_outputs" - case developer - } - } - - let model = try! JSONDecoder().decode(IndieApp.self, from: jsonData) - assert(model.developer.userID == 42) -} - -benchmark("Ananda decoding") { - struct IndieApp: AnandaModel { - struct Developer: AnandaModel { - let userID: Int - let username: String - let email: String - let websiteURL: URL - - init(json: AnandaJSON) { - userID = json.user_id.int() - username = json.username.string() - email = json.email.string() - websiteURL = json.website_url.url() - } - } - - let name: String - let introduction: String - let supportedOutputs: [String] - let developer: Developer - - init(json: AnandaJSON) { - name = json.name.string() - introduction = json.introduction.string() - supportedOutputs = json.supported_outputs.array().map { $0.string() } - developer = .init(json: json.developer) - } - } - - let model = IndieApp(jsonData) - assert(model.developer.userID == 42) -} - -benchmark("Ananda decoding with Macro") { - @AnandaInit - struct IndieApp: AnandaModel { - @AnandaInit - struct Developer: AnandaModel { - @AnandaKey("user_id") - let userID: Int - let username: String - let email: String - @AnandaKey("website_url") - let websiteURL: URL - } - - let name: String - let introduction: String - @AnandaKey("supported_outputs") - let supportedOutputs: [String] - let developer: Developer - } - - let model = IndieApp(jsonData) - assert(model.developer.userID == 42) -} - -Benchmark.main()