Add back iterator for Elements, count test iterations

This commit is contained in:
Garth Snyder 2019-12-19 18:01:46 -08:00
parent ed6fec2809
commit 563e0c3476
2 changed files with 22 additions and 19 deletions

View File

@ -586,25 +586,25 @@ extension Elements: Equatable {
/**
* Elements RandomAccessCollection
*/
//extension Elements: RandomAccessCollection {
// public subscript(position: Int) -> Element {
// return this[position]
// }
//
// public var startIndex: Int {
// return this.startIndex
// }
//
// public var endIndex: Int {
// return this.endIndex
// }
//
// /// The number of Element objects in the collection.
// /// Equivalent to `size()`
// public var count: Int {
// return this.count
// }
//}
extension Elements: RandomAccessCollection {
public subscript(position: Int) -> Element {
return this[position]
}
public var startIndex: Int {
return this.startIndex
}
public var endIndex: Int {
return this.endIndex
}
/// The number of Element objects in the collection.
/// Equivalent to `size()`
public var count: Int {
return this.count
}
}
/**
* Elements IteratorProtocol.

View File

@ -23,16 +23,19 @@ class ParserBenchmark: XCTestCase {
}
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")
}
}