Skip to content

Commit 8d09890

Browse files
Swim benchmarks no longer use a custom renderer (now uses its native one)
- updated benchmark pngs
1 parent 728431c commit 8d09890

File tree

7 files changed

+27
-52
lines changed

7 files changed

+27
-52
lines changed

Benchmarks/Benchmarks/Benchmarks/Benchmarks.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ let benchmarks = {
2727
"Plot" : PlotTests(),
2828
"Pointfreeco" : SwiftHTMLPFTests(),
2929
"SwiftHTMLKit" : SwiftHTMLKitTests(),
30-
"Swim (custom renderer)" : SwimTests(),
30+
"Swim" : SwimTests(),
3131
"VaporHTMLKit" : VaporHTMLKitTests(),
3232
"Vaux (custom renderer)" : VauxTests()
3333
]
3434

35-
for (key, value) in libraries {
35+
/*for (key, value) in libraries {
3636
Benchmark(key) {
3737
for _ in $0.scaledIterations {
3838
blackHole(value.staticHTML())
3939
}
4040
}
41-
}
41+
}*/
4242

43-
/*let context:HTMLContext = HTMLContext()
43+
let context:HTMLContext = HTMLContext()
4444
for (key, value) in libraries {
4545
Benchmark(key) {
4646
for _ in $0.scaledIterations {
4747
blackHole(value.dynamicHTML(context))
4848
}
4949
}
50-
}*/
50+
}
5151
}

Benchmarks/Benchmarks/Swim/Swim.swift

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,11 @@
88
import Utilities
99
import Swim
1010

11-
extension Node {
12-
var rendered : String {
13-
switch self {
14-
case .element(let name, let attributes, let child):
15-
var attributes_string:String = ""
16-
for (key, value) in attributes {
17-
attributes_string += " " + key + "=\"" + value + "\""
18-
}
19-
return (name == "html" ? "<!DOCTYPE html>" : "") + "<" + name + attributes_string + ">" + (child?.rendered ?? "") + (isVoid(name) ? "" : "</" + name + ">")
20-
case .text(let string): return string
21-
case .raw(let string): return string
22-
case .comment(_): return ""
23-
case .documentType(let string): return string
24-
case .fragment(let children):
25-
var string:String = ""
26-
for child in children {
27-
string += child.rendered
28-
}
29-
return string
30-
case .trim: return ""
31-
}
32-
}
33-
func isVoid(_ tag: String) -> Bool {
34-
switch tag {
35-
case "area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr": return true
36-
default: return false
37-
}
38-
}
39-
}
40-
4111
package struct SwimTests : HTMLGenerator {
4212
package init() {}
4313

4414
package func staticHTML() -> String {
15+
var string:String = ""
4516
html {
4617
head {
4718
title { "StaticView" }
@@ -51,14 +22,17 @@ package struct SwimTests : HTMLGenerator {
5122
"Swift HTML Benchmarks"
5223
}
5324
}
54-
}.rendered
25+
}.write(to: &string)
26+
return string
5527
}
28+
5629
package func dynamicHTML(_ context: HTMLContext) -> String {
30+
var string:String = ""
5731
var test:[Node] = []
5832
for quality in context.user.qualities {
5933
test.append(li { quality } )
6034
}
61-
return html {
35+
html {
6236
head {
6337
meta(charset: context.charset)
6438
title { context.title }
@@ -74,6 +48,7 @@ package struct SwimTests : HTMLGenerator {
7448
h3 { context.user.qualities_heading }
7549
ul(id: context.user.qualities_id) { test }
7650
}
77-
}.rendered
51+
}.write(to: &string)
52+
return string
7853
}
7954
}

Benchmarks/Benchmarks/UnitTests/UnitTests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,31 @@ struct UnitTests {
2828
"SwiftHTMLKit" : SwiftHTMLKitTests(),
2929
"Swim" : SwimTests(),
3030
"VaporHTMLKit" : VaporHTMLKitTests(),
31-
"Vaux" : VauxTests()
31+
"Vaux (custom renderer)" : VauxTests()
3232
]
3333
@Test func staticHTML() {
34-
let expected_value:String = #html(
35-
#head(
36-
#title("StaticView")
37-
),
38-
#body(
39-
#h1("Swift HTML Benchmarks")
40-
)
41-
)
34+
let expected_value:String = libraries["SwiftHTMLKit"]!.staticHTML()
35+
// Swim doesn't minify (keeps new line characters and some whitespace)
4236
for (key, value) in libraries {
4337
var string:String = value.staticHTML()
4438
if key == "Swim" {
45-
string = string.replacingOccurrences(of: "\n", with: "")
39+
string.replace("\n", with: "")
4640
}
4741
#expect(string == expected_value, Comment(rawValue: key))
4842
}
4943
}
5044
@Test func dynamicHTML() {
5145
let context:HTMLContext = HTMLContext()
5246
let expected_value:String = libraries["SwiftHTMLKit"]!.dynamicHTML(context)
53-
// Plot closes void tags | Swim uses a dictionary for meta values | Vaux is doodoo
47+
// Plot closes void tags
48+
// Swim doesn't minify (keeps new line characters and some whitespace); uses a dictionary for meta values; closes void tags
49+
// Vaux is doodoo
5450
for (key, value) in libraries {
55-
#expect(value.dynamicHTML(context) == expected_value, Comment(rawValue: key))
51+
var string:String = value.dynamicHTML(context)
52+
if key == "Swim" {
53+
string.replace("\n", with: "")
54+
}
55+
#expect(string == expected_value, Comment(rawValue: key))
5656
}
5757
}
5858
}

Benchmarks/Benchmarks/Utilities/Utilities.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ package struct HTMLContext {
7171
Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec sed diam eget nibh semper varius. Phasellus sed feugiat turpis, sit amet pharetra erat. Integer eleifend tortor ut mauris lobortis consequat. Aliquam fermentum mollis fringilla. Morbi et enim in ligula luctus facilisis quis sed leo. Nullam ut suscipit arcu, eu hendrerit eros. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla maximus tempus dui. In aliquam neque ut urna euismod, vitae ullamcorper nisl fermentum. Integer ac ultricies erat, id volutpat leo. Morbi faucibus tortor at lectus feugiat, quis ultricies lectus dictum. Pellentesque congue blandit ligula, nec convallis lectus volutpat congue. Nam lobortis sapien nec nulla accumsan, a pharetra quam convallis. Donec vulputate rutrum dolor ac cursus. Mauris condimentum convallis malesuada.
7272
7373
Mauris eros quam, dictum id elementum et, pharetra in metus. Quisque fermentum congue risus, accumsan consectetur neque aliquam quis. Vestibulum ipsum massa, euismod faucibus est in, condimentum venenatis risus. Quisque congue vehicula tellus, et dignissim augue accumsan ac. Pellentesque tristique ornare ligula, vitae iaculis dui varius vel. Ut sed sem sed purus facilisis porta quis eu tortor. Donec in vehicula tortor. Sed eget aliquet enim. Mauris tincidunt placerat risus, ut gravida lacus vehicula eget. Curabitur ultrices sapien tortor, eu gravida velit efficitur sed. Suspendisse eu volutpat est, ut bibendum velit. Maecenas mollis sit amet sapien laoreet pulvinar. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Morbi lorem ante, volutpat et accumsan a, fermentum vel metus.
74-
"""
74+
""".replacingOccurrences(of: "\n", with: "")
7575
var string:String = lorem_ipsum
7676
/*for _ in 1..<10 {
7777
string += lorem_ipsum

Benchmarks/img/throughput_dynamic.png

-2.98 KB
Loading

Benchmarks/img/throughput_static.png

-2.28 KB
Loading

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Use the `HTMLElementAttribute.event(<type>, "<value>")`.
180180
- [JohnSundell/Plot](https://github.com/JohnSundell/Plot) v0.14.0
181181
- [RandomHashTags/swift-htmlkit](https://github.com/RandomHashTags/swift-htmlkit) v0.6.0 (this library)
182182
- [pointfreeco/swift-html](https://github.com/pointfreeco/swift-html) v0.4.1
183-
- [robb/Swim](https://github.com/robb/Swim) v0.4.0 (patched version [here](https://github.com/RandomHashTags/fork-Swim); custom renderer [here](https://github.com/RandomHashTags/swift-htmlkit/blob/main/Benchmarks/Benchmarks/Swim/Swim.swift))
183+
- [robb/Swim](https://github.com/robb/Swim) v0.4.0 (patched version [here](https://github.com/RandomHashTags/fork-Swim))
184184
- [vapor-community/HTMLKit](https://github.com/vapor-community/HTMLKit) v2.8.1
185185
- [dokun1/Vaux](https://github.com/dokun1/Vaux) v0.2.0 (patched version [here](https://github.com/RandomHashTags/fork-Vaux); custom renderer [here](https://github.com/RandomHashTags/swift-htmlkit/blob/main/Benchmarks/Benchmarks/Vaux/Vaux.swift))
186186

0 commit comments

Comments
 (0)