-
-
Notifications
You must be signed in to change notification settings - Fork 351
/
ParserBenchmark.swift
42 lines (36 loc) · 1.11 KB
/
ParserBenchmark.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// ParserBenchmark.swift
// SwiftSoupTests
//
// Created by garth on 2/26/19.
// Copyright © 2019 Nabil Chatbi. All rights reserved.
//
import XCTest
import SwiftSoup
class ParserBenchmark: XCTestCase {
enum Const {
static var corpusHTMLData: [String] = []
static let repetitions = 5
}
override func setUp() {
let bundle = Bundle(for: type(of: self))
let urls = bundle.urls(forResourcesWithExtension: ".html", subdirectory: nil)
Const.corpusHTMLData = urls!.compactMap { try? Data(contentsOf: $0) }.map { String(decoding: $0, as: UTF8.self) }
}
func testParserPerformance() throws {
var count = 0
measure {
for htmlDoc in Const.corpusHTMLData {
for _ in 1...Const.repetitions {
do {
let _ = try SwiftSoup.parse(htmlDoc)
count += 1
} catch {
XCTFail("Exception while parsing HTML")
}
}
}
print("Did \(count) iterations")
}
}
}