Skip to content

Commit 8cc8280

Browse files
add benchmark results to README
- also added `Plot` to compare
1 parent a906a6b commit 8cc8280

File tree

7 files changed

+314
-41
lines changed

7 files changed

+314
-41
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ DerivedData
99
Package.resolved
1010
__BenchmarkBoilerplate.d
1111
__BenchmarkBoilerplate.o
12-
__BenchmarkBoilerplate.swiftdeps
12+
__BenchmarkBoilerplate.swiftdeps
13+
__BenchmarkBoilerplate.swiftdeps~

Benchmarks/Benchmarks/Benchmarks/Benchmarks.swift

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,30 @@
66
//
77

88
import Benchmark
9-
import TestSwiftHTMLKit
9+
import Utilities
10+
1011
import TestElementary
12+
import TestPlot
13+
import TestSwiftHTMLKit
1114
import TestSwiftHTMLPF
15+
import TestVaporHTMLKit
1216

1317
let benchmarks = {
1418
Benchmark.defaultConfiguration = .init(metrics: .all)
1519

16-
let swifthtmlkit:SwiftHTMLKitTests = SwiftHTMLKitTests()
17-
Benchmark("SwiftHTMLKit simpleHTML()") {
18-
for _ in $0.scaledIterations {
19-
blackHole(swifthtmlkit.simpleHTML())
20-
}
21-
}
22-
23-
let elementary:ElementaryTests = ElementaryTests()
24-
Benchmark("Elementary simpleHTML()") {
25-
for _ in $0.scaledIterations {
26-
blackHole(elementary.simpleHTML())
27-
}
28-
}
29-
30-
/*let renderer:Renderer = Renderer.init()
31-
Benchmark("VaporHTMLKit create single html") {
32-
for _ in $0.scaledIterations {
33-
blackHole(renderer.render(view: VaporHTMLKitTests.SimpleHTML()))
34-
}
35-
}*/
36-
37-
let swifthtml:SwiftHTMLPFTests = SwiftHTMLPFTests()
38-
Benchmark("SwiftHtml singleHTML()") {
39-
for _ in $0.scaledIterations {
40-
blackHole(swifthtml.simpleHTML())
41-
}
42-
}
43-
}
20+
let libraries:[String:HTMLGenerator] = [
21+
"Elementary" : ElementaryTests(),
22+
"Plot" : PlotTests(),
23+
"SwiftHTMLKit" : SwiftHTMLKitTests(),
24+
"SwiftHTMLPF" : SwiftHTMLPFTests(),
25+
"VaporHTMLKit" : VaporHTMLKitTests()
26+
]
4427

45-
/*struct VaporHTMLKitTests {
46-
struct SimpleHTML : some VaporHTMLKit.View {
47-
var body : Content {
48-
Html {
49-
Body {
50-
Heading1 { "Swift HTML Benchmarks" }
51-
}
28+
for (key, value) in libraries {
29+
Benchmark(key + " simpleHTML()") {
30+
for _ in $0.scaledIterations {
31+
blackHole(value.simpleHTML())
5232
}
5333
}
5434
}
55-
}*/
35+
}

Benchmarks/Benchmarks/Plot/Plot.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Plot.swift
3+
//
4+
//
5+
// Created by Evan Anderson on 10/5/24.
6+
//
7+
8+
import Utilities
9+
import Plot
10+
11+
package struct PlotTests : HTMLGenerator {
12+
package init() {}
13+
14+
package func simpleHTML() -> String {
15+
HTML(
16+
.body(
17+
.h1("Swift HTML Benchmarks")
18+
)
19+
).render()
20+
}
21+
package func optimalHTML() -> String {
22+
simpleHTML()
23+
}
24+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// SwiftHTMLBB.swift
3+
//
4+
//
5+
// Created by Evan Anderson on 10/5/24.
6+
//
7+
8+
import Utilities
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// VaporHTMLKit.swift
3+
//
4+
//
5+
// Created by Evan Anderson on 10/5/24.
6+
//
7+
8+
import Utilities
9+
import VaporHTMLKit
10+
11+
package struct VaporHTMLKitTests : HTMLGenerator {
12+
13+
let renderer:Renderer
14+
package init() {
15+
renderer = Renderer()
16+
try! renderer.add(layout: SimpleView())
17+
}
18+
19+
package func simpleHTML() -> String {
20+
return try! renderer.render(layout: SimpleView.self)
21+
}
22+
package func optimalHTML() -> String {
23+
simpleHTML()
24+
}
25+
}
26+
27+
struct SimpleView : View {
28+
var body : AnyContent {
29+
Document(.html5)
30+
Html {
31+
Body {
32+
Heading1 { "Swift HTML Benchmarks" }
33+
}
34+
}
35+
}
36+
}

Benchmarks/Package.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ let package = Package(
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"),
1717
//.package(name: "BBHTML", url: "https://github.com/BinaryBirds/swift-html", from: "1.7.0")
18+
.package(url: "https://github.com/JohnSundell/Plot", from: "0.14.0")
1819
],
1920
targets: [
2021
.target(
@@ -29,6 +30,14 @@ let package = Package(
2930
],
3031
path: "Benchmarks/Elementary"
3132
),
33+
.target(
34+
name: "TestPlot",
35+
dependencies: [
36+
"Utilities",
37+
.product(name: "Plot", package: "Plot")
38+
],
39+
path: "Benchmarks/Plot"
40+
),
3241
.target(
3342
name: "TestSwiftHTMLBB",
3443
dependencies: [
@@ -67,7 +76,9 @@ let package = Package(
6776
.executableTarget(
6877
name: "Benchmarks",
6978
dependencies: [
79+
"Utilities",
7080
"TestElementary",
81+
"TestPlot",
7182
"TestSwiftHTMLBB",
7283
"TestSwiftHTMLKit",
7384
"TestSwiftHTMLPF",

0 commit comments

Comments
 (0)