Skip to content

More idiomatic elmentary benchmark code #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions Benchmarks/Benchmarks/Elementary/Elementary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,31 @@ package struct ElementaryTests : HTMLGenerator {
package func staticHTML() -> String {
StaticView().render()
}

package func dynamicHTML(_ context: HTMLContext) -> String {
DynamicView(context: context).rawHTML.render()
DynamicView(context: context).render()
}
}

struct StaticView : HTMLDocument {
var title:String = "StaticView"

var head : some HTML {
""
}
var body : some HTML {
h1 { "Swift HTML Benchmarks" }
struct StaticView: HTML {
var content: some HTML {
HTMLRaw("<!DOCTYPE html>")
html {
head {
title { "StaticView" }
}
body {
h1 { "Swift HTML Benchmarks" }
}
}
}
}

struct DynamicView {
struct DynamicView: HTML {
let context:HTMLContext

// Elementary puts the title element first in the head, which is wrong; it needs to be charset | this is a workaround
@HTMLBuilder var rawHTML : some HTML {
var content : some HTML {
HTMLRaw("<!DOCTYPE html>")
html {
head {
Expand All @@ -45,12 +49,12 @@ struct DynamicView {
}
body {
h1 { context.heading }
div(attributes: [.id(context.desc_id)]) {
div(.id(context.desc_id)) {
p { context.string }
}
h2 { context.user.details_heading }
h3 { context.user.qualities_heading }
ul(attributes: [.id(context.user.qualities_id)]) {
ul(.id(context.user.qualities_id)) {
for quality in context.user.qualities {
li { quality }
}
Expand Down