Skip to content

Instantly share code, notes, and snippets.

@jgaskins
Last active September 5, 2024 19:24
Show Gist options
  • Save jgaskins/ba2bda6b56cb7a8702e61fd31f6738ed to your computer and use it in GitHub Desktop.
Save jgaskins/ba2bda6b56cb7a8702e61fd31f6738ed to your computer and use it in GitHub Desktop.
Benchmarking Phlex-like components in Armature
➜ armature git:(master) ✗ crystal run --release bench_code_component.cr
name 815.75k ( 1.23µs) (± 5.66%) 336B/op fastest
require "benchmark"
require "../src/component"
record NestedNameComponent < Armature::Component, name : String do
render do
3.times do
div(class: "users") do
h2 { "#{@name} message" }
p(id: "user-#{@name}") do
span(class: "title") { "they:" }
span(class: "message") { "nested hello #{@name}" }
end
end
end
end
end
buffer = IO::Memory.new(1 << 16)
Benchmark.ips do |x|
x.report "name" { NestedNameComponent.new(name: "Fox Mulder").to_s buffer.rewind }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment