From 563e0c3476d45df5a657cb85ffb5838f9c376d22 Mon Sep 17 00:00:00 2001 From: Garth Snyder Date: Thu, 19 Dec 2019 18:01:46 -0800 Subject: [PATCH] Add back iterator for Elements, count test iterations --- Sources/Elements.swift | 38 +++++++++++++++---------------- Tests-macOS/ParserBenchmark.swift | 3 +++ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Sources/Elements.swift b/Sources/Elements.swift index 347b2d4..62b50cd 100644 --- a/Sources/Elements.swift +++ b/Sources/Elements.swift @@ -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. diff --git a/Tests-macOS/ParserBenchmark.swift b/Tests-macOS/ParserBenchmark.swift index 14602d7..cf8e821 100644 --- a/Tests-macOS/ParserBenchmark.swift +++ b/Tests-macOS/ParserBenchmark.swift @@ -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") } }