Skip to content

Commit c905768

Browse files
README updates; added benchmarks for dynamic pages
- removed existing README benchmarks; benchmarks now are displayed as images
1 parent 198ec73 commit c905768

File tree

16 files changed

+206
-184
lines changed

16 files changed

+206
-184
lines changed

Benchmarks/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ DerivedData/
1010
Package.resolved
1111
__BenchmarkBoilerplate.d
1212
__BenchmarkBoilerplate.o
13-
__BenchmarkBoilerplate.swiftdeps
13+
__BenchmarkBoilerplate.swiftdeps
14+
Current_run.jmh.json

Benchmarks/Benchmarks/Benchmarks/Benchmarks.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,19 @@ let benchmarks = {
3030
]
3131

3232
for (key, value) in libraries {
33-
Benchmark(key + " simpleHTML()") {
33+
Benchmark(key + " static") {
3434
for _ in $0.scaledIterations {
35-
blackHole(value.simpleHTML())
35+
blackHole(value.staticHTML())
3636
}
3737
}
3838
}
39+
40+
/*let context:HTMLContext = HTMLContext()
41+
for (key, value) in libraries {
42+
Benchmark(key + " dynamic") {
43+
for _ in $0.scaledIterations {
44+
blackHole(value.dynamicHTML(context))
45+
}
46+
}
47+
}*/
3948
}

Benchmarks/Benchmarks/Elementary/Elementary.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,24 @@ import Elementary
1111
package struct ElementaryTests : HTMLGenerator {
1212
package init() {}
1313

14-
package func simpleHTML() -> String {
14+
package func staticHTML() -> String {
1515
html { body { h1 { "Swift HTML Benchmarks" }} }.render()
1616
}
17-
package func optimalHTML() -> String {
18-
simpleHTML()
17+
package func dynamicHTML(_ context: HTMLContext) -> String {
18+
html {
19+
body {
20+
h1 { context.heading }
21+
div(attributes: [.id("desc")]) {
22+
p { context.string }
23+
}
24+
h2 { context.user.details_heading }
25+
h3 { context.user.qualities_heading }
26+
ul(attributes: [.id("user-qualities")]) {
27+
for quality in context.user.qualities {
28+
li { quality }
29+
}
30+
}
31+
}
32+
}.render()
1933
}
2034
}

Benchmarks/Benchmarks/Leaf/Leaf.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
// Created by Evan Anderson on 10/8/24.
66
//
77

8-
import Utilities
8+
import Utilities
9+
10+
package struct LeafTests {
11+
}

Benchmarks/Benchmarks/Plot/Plot.swift

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,40 @@ import Plot
1111
package struct PlotTests : HTMLGenerator {
1212
package init() {}
1313

14-
package func simpleHTML() -> String {
14+
package func staticHTML() -> String {
1515
HTML(
1616
.body(
1717
.h1("Swift HTML Benchmarks")
1818
)
1919
).render()
2020
}
21-
package func optimalHTML() -> String {
22-
simpleHTML()
21+
package func dynamicHTML(_ context: Utilities.HTMLContext) -> String {
22+
let context:Context = Context(context)
23+
return HTML(
24+
.body(
25+
.component(context.heading),
26+
.component(context.desc),
27+
.component(context.details_heading),
28+
.component(context.qualities_heading),
29+
.component(context.qualities)
30+
)
31+
)
32+
.render()
33+
}
34+
}
35+
36+
struct Context {
37+
let heading:any Component
38+
let desc:any Component
39+
let details_heading:any Component
40+
let qualities_heading:any Component
41+
let qualities:any Component
42+
43+
init(_ context: Utilities.HTMLContext) {
44+
heading = H1(context.heading)
45+
desc = Div(Paragraph(context.string).id("desc"))
46+
details_heading = H2(context.user.details_heading)
47+
qualities_heading = H3(context.user.qualities_heading)
48+
qualities = List(context.user.qualities).id("user-qualities")
2349
}
2450
}

Benchmarks/Benchmarks/SwiftHTMLBB/SwiftHTMLBB.swift

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

8-
import Utilities
8+
import Utilities
9+
10+
package struct SwiftHTMLBBTests {
11+
}

Benchmarks/Benchmarks/SwiftHTMLKit/SwiftHTMLKit.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,25 @@ import SwiftHTMLKit
1111
package struct SwiftHTMLKitTests : HTMLGenerator {
1212
package init() {}
1313

14-
package func simpleHTML() -> String {
14+
package func staticHTML() -> String {
1515
#html([
1616
#body([
1717
#h1(["Swift HTML Benchmarks"])
1818
])
1919
])
2020
}
21-
package func optimalHTML() -> String { simpleHTML() }
21+
package func dynamicHTML(_ context: HTMLContext) -> String {
22+
let qualities:String = context.user.qualities.map({ #li(["\($0)"]) }).joined()
23+
return #html([
24+
#body([
25+
#h1(["\(context.heading)"]),
26+
#div(attributes: [.id("desc")], [
27+
#p(["\(context.string)"])
28+
]),
29+
#h2(["\(context.user.details_heading)"]),
30+
#h3(["\(context.user.qualities_heading)"]),
31+
#ul(attributes: [.id("user-qualities")], ["\(qualities)"])
32+
])
33+
])
34+
}
2235
}

Benchmarks/Benchmarks/SwiftHTMLPF/SwiftHTMLPF.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,23 @@ import Html
1111
package struct SwiftHTMLPFTests : HTMLGenerator {
1212
package init() {}
1313

14-
package func simpleHTML() -> String {
14+
package func staticHTML() -> String {
1515
render(.document(.html(.body(.h1("Swift HTML Benchmarks")))))
1616
}
17-
package func optimalHTML() -> String {
18-
simpleHTML()
17+
18+
package func dynamicHTML(_ context: HTMLContext) -> String {
19+
render(
20+
.document(
21+
.html(
22+
.body(
23+
.h1(.raw(context.heading)),
24+
.div(attributes: [.id("desc")], .p(.raw(context.string))),
25+
.h2(.raw(context.user.details_heading)),
26+
.h3(.raw(context.user.qualities_heading)),
27+
.ul(attributes: [.id("user-qualities")], .fragment(context.user.qualities.map({ quality in .li(.raw(quality)) })))
28+
)
29+
)
30+
)
31+
)
1932
}
2033
}

Benchmarks/Benchmarks/Swim/Swim.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import HTML
1313
package struct SwimTests : HTMLGenerator {
1414
package init() {}
1515

16-
package func simpleHTML() -> String {
16+
package func staticHTML() -> String {
1717
html {
1818
body {
1919
h1 {
@@ -22,7 +22,4 @@ package struct SwimTests : HTMLGenerator {
2222
}
2323
}
2424
}
25-
package func optimalHTML() -> String {
26-
simpleHTML()
27-
}
2825
}*/

Benchmarks/Benchmarks/Toucan/Toucan.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@
33
//
44
//
55
// Created by Evan Anderson on 10/6/24.
6-
//
6+
//
7+
8+
import Utilities
9+
10+
package struct ToucanTests {
11+
}

0 commit comments

Comments
 (0)