Skip to content

Commit 0fc4e01

Browse files
added 2 more benchmarked projects; updated benchmark pngs
1 parent b56c0d0 commit 0fc4e01

File tree

8 files changed

+91
-27
lines changed

8 files changed

+91
-27
lines changed

.gitignore

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ DerivedData
77
.netrc
88
.vscode
99
Package.resolved
10-
__BenchmarkBoilerplate.d
11-
__BenchmarkBoilerplate.o
12-
__BenchmarkBoilerplate.swiftdeps
13-
__BenchmarkBoilerplate.swiftdeps~
14-
Tag.d
15-
Tag.o
16-
Tag.swiftdeps
17-
Tags.d
10+
__BenchmarkBoilerplate.*
11+
Aria.*
12+
Attributes.*
13+
ChildOf.*
14+
DebugRender.*
15+
DebugXmlRender.*
16+
Elements.*
17+
Events.*
18+
Html4.*
19+
HtmlRender.*
20+
MediaType.*
21+
Node.*
22+
Tag.*
23+
Tags.*
24+
XmlRender.*

Benchmarks/Benchmarks/Benchmarks/Benchmarks.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Utilities
1010

1111
import TestElementary
1212
import TestPlot
13+
import TestSwiftHTMLBB
1314
import TestSwiftHTMLKit
1415
import TestSwiftHTMLPF
1516
import TestSwim
@@ -21,28 +22,29 @@ let benchmarks = {
2122
Benchmark.defaultConfiguration = .init(metrics: .all)
2223

2324
let libraries:[String:HTMLGenerator] = [
25+
"BinaryBirds" : SwiftHTMLBBTests(),
2426
"Elementary" : ElementaryTests(),
2527
"Plot" : PlotTests(),
28+
"Pointfreeco" : SwiftHTMLPFTests(),
2629
"SwiftHTMLKit" : SwiftHTMLKitTests(),
27-
"SwiftHTMLPF" : SwiftHTMLPFTests(),
28-
//"Swim" : SwimTests(),
30+
"Swim" : SwimTests(),
2931
"VaporHTMLKit" : VaporHTMLKitTests()
3032
]
3133

32-
for (key, value) in libraries {
33-
Benchmark(key + " static") {
34+
/*for (key, value) in libraries {
35+
Benchmark(key) {
3436
for _ in $0.scaledIterations {
3537
blackHole(value.staticHTML())
3638
}
3739
}
38-
}
40+
}*/
3941

40-
/*let context:HTMLContext = HTMLContext()
42+
let context:HTMLContext = HTMLContext()
4143
for (key, value) in libraries {
42-
Benchmark(key + " dynamic") {
44+
Benchmark(key) {
4345
for _ in $0.scaledIterations {
4446
blackHole(value.dynamicHTML(context))
4547
}
4648
}
47-
}*/
49+
}
4850
}

Benchmarks/Benchmarks/SwiftHTMLBB/SwiftHTMLBB.swift

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,39 @@
66
//
77

88
import Utilities
9+
import SwiftHtml
910

10-
package struct SwiftHTMLBBTests {
11+
package struct SwiftHTMLBBTests : HTMLGenerator {
12+
let renderer:DocumentRenderer
13+
package init() {
14+
renderer = DocumentRenderer(minify: true, indent: 0)
15+
}
16+
17+
package func staticHTML() -> String {
18+
renderer.render(Document(.html) {
19+
Html {
20+
Body {
21+
H1("Swift HTML Benchmarks")
22+
}
23+
}
24+
})
25+
}
26+
27+
package func dynamicHTML(_ context: HTMLContext) -> String {
28+
renderer.render(Document(.html) {
29+
Html {
30+
Body {
31+
H1(context.heading)
32+
Div {
33+
P(context.string)
34+
}.id("desc")
35+
H2(context.user.details_heading)
36+
H3(context.user.qualities_heading)
37+
Ul {
38+
context.user.qualities.map({ Li($0) })
39+
}.id("user-qualities")
40+
}
41+
}
42+
})
43+
}
1144
}

Benchmarks/Benchmarks/Swim/Swim.swift

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
// Created by Evan Anderson on 10/6/24.
66
//
77

8-
/*
98
import Utilities
109
import Swim
11-
import HTML
10+
11+
extension Node {
12+
var rendered: String {
13+
var result = ""
14+
write(to: &result)
15+
return result
16+
}
17+
}
1218

1319
package struct SwimTests : HTMLGenerator {
1420
package init() {}
@@ -20,6 +26,21 @@ package struct SwimTests : HTMLGenerator {
2026
"Swift HTML Benchmarks"
2127
}
2228
}
23-
}
29+
}.rendered
30+
}
31+
package func dynamicHTML(_ context: HTMLContext) -> String {
32+
html {
33+
body {
34+
h1 { context.heading }
35+
div(id: "desc") {
36+
p { context.string }
37+
}
38+
h2 { context.user.details_heading }
39+
h3 { context.user.qualities_heading }
40+
ul(id: "user-qualities") {
41+
context.user.qualities.map({ quality in li { quality} })
42+
}
43+
}
44+
}.rendered
2445
}
25-
}*/
46+
}

Benchmarks/Package.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ let package = Package(
1414
.package(url: "https://github.com/sliemeobn/elementary", from: "0.3.4"),
1515
.package(url: "https://github.com/vapor-community/HTMLKit", from: "2.8.1"),
1616
.package(url: "https://github.com/pointfreeco/swift-html", from: "0.4.1"),
17-
//.package(name: "BBHTML", url: "https://github.com/BinaryBirds/swift-html", from: "1.7.0") // conflicting package name
17+
.package(url: "https://github.com/RandomHashTags/fork-bb-swift-html", branch: "main"),
1818
.package(url: "https://github.com/JohnSundell/Plot", from: "0.14.0"),
1919
//.package(url: "https://github.com/toucansites/toucan", from: "1.0.0-alpha.1"), // unstable
20-
//.package(url: "https://github.com/robb/Swim", from: "0.4.0"), // compile problem
20+
.package(url: "https://github.com/RandomHashTags/fork-Swim", branch: "main"),
2121
.package(url: "https://github.com/dokun1/Vaux", from: "0.2.0"), // result limitation
2222
.package(url: "https://github.com/vapor/leaf", from: "4.4.0"),
2323
],
@@ -54,7 +54,7 @@ let package = Package(
5454
name: "TestSwiftHTMLBB",
5555
dependencies: [
5656
"Utilities",
57-
//.product(name: "SwiftHtml", package: "BBHTML")
57+
.product(name: "SwiftHtml", package: "fork-bb-swift-html")
5858
],
5959
path: "Benchmarks/SwiftHTMLBB"
6060
),
@@ -71,16 +71,15 @@ let package = Package(
7171
name: "TestSwiftHTMLPF",
7272
dependencies: [
7373
"Utilities",
74-
.product(name: "Html", package: "swift-html"),
74+
.product(name: "Html", package: "swift-html")
7575
],
7676
path: "Benchmarks/SwiftHTMLPF"
7777
),
7878
.target(
7979
name: "TestSwim",
8080
dependencies: [
8181
"Utilities",
82-
/*.product(name: "Swim", package: "Swim"),
83-
.product(name: "HTML", package: "Swim")*/
82+
.product(name: "Swim", package: "fork-Swim")
8483
],
8584
path: "Benchmarks/Swim"
8685
),
9.29 KB
Loading
15.5 KB
Loading

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,12 @@ Use the `HTMLElementAttribute.event(<type>, "<value>")`.
148148

149149
## Benchmarks
150150
- Libraries tested
151+
- [BinaryBuilds/swift-html](https://github.com/BinaryBirds/swift-html) v1.7.0 (fixed version [here](https://github.com/RandomHashTags/fork-bb-swift-html))
151152
- [sliemeobn/elementary](https://github.com/sliemeobn/elementary) v0.3.4
152153
- [JohnSundell/Plot](https://github.com/JohnSundell/Plot) v0.14.0
153154
- [RandomHashTags/swift-htmlkit](https://github.com/RandomHashTags/swift-htmlkit) v0.5.0 (this library)
154155
- [pointfreeco/swift-html](https://github.com/pointfreeco/swift-html) v0.4.1
156+
- [robb/Swim](https://github.com/robb/Swim) v0.4.0 (fixed version [here](https://github.com/RandomHashTags/fork-Swim))
155157
- [vapor-community/HTMLKit](https://github.com/vapor-community/HTMLKit) v2.8.1
156158

157159
Using iMac (i9 9900k, 72GB RAM, 2TB) with macOS 15.0 and the Swift 6 compiler.

0 commit comments

Comments
 (0)