Skip to content

Commit 0d6346a

Browse files
committed
PoC for TDS Perf Tests
1 parent 5de0a61 commit 0d6346a

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

.swiftpm/xcode/xcshareddata/xcschemes/TrackerRadarKit.xcscheme

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@
5353
ReferencedContainer = "container:">
5454
</BuildableReference>
5555
</TestableReference>
56+
<TestableReference
57+
skipped = "NO">
58+
<BuildableReference
59+
BuildableIdentifier = "primary"
60+
BlueprintIdentifier = "TrackerRadarKitPerformanceTests"
61+
BuildableName = "TrackerRadarKitPerformanceTests"
62+
BlueprintName = "TrackerRadarKitPerformanceTests"
63+
ReferencedContainer = "container:">
64+
</BuildableReference>
65+
</TestableReference>
5666
</Testables>
5767
</TestAction>
5868
<LaunchAction

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ let package = Package(
3737
resources: [
3838
.process("Resources/trackerData.json"),
3939
.process("Resources/mockTrackerData.json")
40-
])
40+
]),
41+
.testTarget(
42+
name: "TrackerRadarKitPerformanceTests",
43+
dependencies: ["TrackerRadarKit"])
4144
]
4245
)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//
2+
// NextTrackerDataSetPerformanceTests.swift
3+
//
4+
// Copyright © 2021 DuckDuckGo. All rights reserved.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
19+
20+
import Foundation
21+
import XCTest
22+
import TrackerRadarKit
23+
import WebKit
24+
25+
class NextTrackerDataSetPerformanceTests: XCTestCase {
26+
27+
static func nextURL(filename: String) -> URL {
28+
return URL(string: "https://staticcdn.duckduckgo.com/trackerblocking/v5/next/\(filename)")!
29+
}
30+
31+
var nextiOSTDS: TrackerData!
32+
33+
34+
override func setUp() async throws {
35+
try await super.setUp()
36+
37+
let (data, _) = try await URLSession.shared.data(from: Self.nextURL(filename: "ios-tds.json"))
38+
39+
nextiOSTDS = try JSONDecoder().decode(TrackerData.self, from: data)
40+
41+
print("Next TDS prepared")
42+
}
43+
44+
func testPerformanceOfNext_iOSTDS() throws {
45+
46+
let rules = ContentBlockerRulesBuilder(trackerData: nextiOSTDS).buildRules()
47+
48+
let data = try JSONEncoder().encode(rules)
49+
let ruleList = String(data: data, encoding: .utf8)!
50+
51+
var store: WKContentRuleListStore!
52+
53+
let warmUpExpectation = expectation(description: "Warmed up")
54+
55+
DispatchQueue.main.async {
56+
store = WKContentRuleListStore(url: FileManager.default.temporaryDirectory)
57+
store.compileContentRuleList(forIdentifier: UUID().uuidString, encodedContentRuleList: ruleList) { _, error in
58+
XCTAssertNil(error)
59+
warmUpExpectation.fulfill()
60+
}
61+
}
62+
wait(for: [warmUpExpectation], timeout: 40)
63+
64+
measure {
65+
let time = CACurrentMediaTime()
66+
let expectation = expectation(description: "Compiled")
67+
68+
store.compileContentRuleList(forIdentifier: UUID().uuidString, encodedContentRuleList: ruleList) { _, error in
69+
XCTAssertNil(error)
70+
71+
Thread.sleep(forTimeInterval: 1)
72+
73+
expectation.fulfill()
74+
}
75+
76+
wait(for: [expectation], timeout: 40)
77+
print("Compiled in \(CACurrentMediaTime() - time)")
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)