Merge pull request #4 from scinfu/develop

Develop
This commit is contained in:
Nabil Chatbi 2016-12-16 21:43:12 +01:00 committed by GitHub
commit e81bc367ca
6 changed files with 199 additions and 4 deletions

View File

@ -14,6 +14,8 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//testPerformanceDiv()
testSite()
}
override func didReceiveMemoryWarning() {
@ -29,6 +31,74 @@ class ViewController: UIViewController {
return doc
}
func testPerformanceDiv() {
let h: String = "<!doctype html>\n" +
"<html>\n" +
" <head></head>\n" +
" <body>\n" +
" <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
" <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
" <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
" <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
" <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
" <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
" <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
" <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
" <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
"<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
" <foo />bar\n" +
" </body>\n" +
"</html>"
let doc: Document = try! SwiftSoup.parse(h);
do {
for _ in 0...100000{
_ = try doc.select("div");
}
}
catch {
}
}
func testSite()
{
let myURLString = "http://apple.com"
guard let myURL = URL(string: myURLString) else {
print("Error: \(myURLString) doesn't seem to be a valid URL")
return
}
let html = try! String(contentsOf: myURL, encoding: .utf8)
let doc: Document = try! SwiftSoup.parse(html)
do {
for _ in 0...100{
_ = try doc.text()
}
}
catch {
print("Error")
}
}
}

View File

@ -146,7 +146,7 @@ open class TextNode : Node {
}
static open func lastCharIsWhitespace(_ sb: StringBuilder)->Bool {
return sb.length != 0 && sb.toString().charAt(sb.length - 1) == " ";
return sb.toString().characters.last == " ";
}
// attribute fiddling. create on first access.

View File

@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = 'SwiftSoup'
s.version = '1.0.1'
s.version = '1.0.2'
s.summary = 'Swift HTML Parser.'
# This description is used to generate tags and improve search results.

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>classNames</key>
<dict>
<key>SwiftSoupTests</key>
<dict>
<key>testPerformanceDiv()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>36.859</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
</dict>
</dict>
</dict>
</plist>

View File

@ -4,6 +4,37 @@
<dict>
<key>runDestinationsByUUID</key>
<dict>
<key>9F80FB9B-4E37-45A8-BFE8-9AF36737A6F3</key>
<dict>
<key>localComputer</key>
<dict>
<key>busSpeedInMHz</key>
<integer>100</integer>
<key>cpuCount</key>
<integer>1</integer>
<key>cpuKind</key>
<string>Intel Core i7</string>
<key>cpuSpeedInMHz</key>
<integer>3100</integer>
<key>logicalCPUCoresPerPackage</key>
<integer>4</integer>
<key>modelCode</key>
<string>MacBookPro12,1</string>
<key>physicalCPUCoresPerPackage</key>
<integer>2</integer>
<key>platformIdentifier</key>
<string>com.apple.platform.macosx</string>
</dict>
<key>targetArchitecture</key>
<string>x86_64</string>
<key>targetDevice</key>
<dict>
<key>modelCode</key>
<string>iPhone7,2</string>
<key>platformIdentifier</key>
<string>com.apple.platform.iphonesimulator</string>
</dict>
</dict>
<key>F9553B46-8F24-4C2B-8A1E-8CC5535D12E1</key>
<dict>
<key>localComputer</key>

View File

@ -29,6 +29,78 @@ class SwiftSoupTests: XCTestCase {
super.tearDown()
}
private func createHtmlDocument(_ charset: String)->Document {
let doc: Document = Document.createShell("");
try! doc.head()?.appendElement("meta").attr("charset", charset);
try! doc.head()?.appendElement("meta").attr("name", "charset").attr("content", charset);
return doc;
}
//average: 58.562,
//passed (586.015 seconds)
// func testPerformanceExample() {
// let h: String = "<!doctype html>\n" +
// "<html>\n" +
// " <head></head>\n" +
// " <body>\n" +
// " <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
// " <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
// " <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
// " <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
// " <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
// " <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
// " <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
// " <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
// " <img async checked src=\"&amp;<>&quot;\">&lt;&gt;&amp;\"\n" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// "<div id=div1><p>Hello</p><p>Another <b>element</b></p><div id=div2><img src=foo.png></div></div>" +
// " <foo />bar\n" +
// " </body>\n" +
// "</html>"
// self.measure {
// do {
// for _ in 0...1000{
// let doc: Document = try! SwiftSoup.parse(h);
// doc.updateMetaCharsetElement(true);
// try doc.charset(String.Encoding.isoLatin2);
//
// _ = try doc.toString()
//
// let selectedElement: Element = try doc.select("meta[charset]").first()!;
// _ = doc.charset().displayName()
// _ = try selectedElement.attr("charset")
// _ = doc.outputSettings().charset()
// _ = try doc.select("div")
// _ = try doc.cssSelector()
// _ = doc.firstElementSibling()
// _ = try doc.getElementsByAttributeValueContaining("key", "mm")
// _ = selectedElement.children()
// _ = try selectedElement.after(" c ")
// _ = try selectedElement.select("dd")
// }
// }
// catch {
// }
// }
// }
//passed (390.343 seconds).
}