Skip to content

Commit

Permalink
Add back iterator for Elements, count test iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
GarthSnyder committed Dec 20, 2019
1 parent ed6fec2 commit 563e0c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
38 changes: 19 additions & 19 deletions Sources/Elements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions Tests-macOS/ParserBenchmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down

0 comments on commit 563e0c3

Please sign in to comment.