Skip to content

Commit

Permalink
playing around with a component that has no Rails/AV dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
patbenatar committed Sep 18, 2024
1 parent 1f93769 commit af02ed5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
25 changes: 25 additions & 0 deletions spec/dummy/app/components/perf_test/fast_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class PerfTest::FastComponent # < Rbexy::Component
# include ActionView::Context
# TEMPLATE = "@output_buffer.safe_concat('<h1>Hello component</h1>'.freeze);@output_buffer.to_s;".freeze

def initialize(view_context)
# @compiled = Rbexy.compile(Rbexy::Template.new("<h1>Hello component</h1>"))
# @runtime = Rbexy::Runtime.new
@output_buffer = ActionView::OutputBuffer.new
# @output_buffer = view_context.instance_variable_get(:@output_buffer)
end

def render_in
# @runtime.evaluate(@compiled)
# @compiled
# instance_eval(TEMPLATE)
template
# instance_eval(@compiled)
# "<h1>Hello component</h1>"
# tag.h2 "Hello component"
end

def template
@output_buffer.safe_concat('<h1>Hello component</h1>'.freeze);@output_buffer.to_s;
end
end
2 changes: 1 addition & 1 deletion spec/dummy/app/controllers/perf_test_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def time
(Time.now.to_f - start.to_f) * 1000
end

avg_duration = (times.sum.to_f / times.count).round(2)
avg_duration = (times.sum.to_f / times.count).round(5)

"<div>Avg time (ms): #{avg_duration}</div>".html_safe
end
Expand Down
16 changes: 14 additions & 2 deletions spec/dummy/app/views/perf_test/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@
<% render "simple_partial" %>
<% end %>

<h1>Rbexy component w/ template</h1>
<h1>Inline HTML</h1>
<%= time do %>
<% PerfTest::SimpleComponent.new(self).render_in %>
<!-- <h1>Hello inline</h1> -->
<% end %>

<h1>Rbexy component w/ call</h1>
<%= time do %>
<% PerfTest::CallComponent.new(self).render_in %>
<% end %>

<h1>Rbexy::Component</h1>
<%= time do %>
<!-- <% PerfTest::SimpleComponent.new(self).render_in %> -->
<% end %>

<h1>Rbexy::FastComponent</h1>
<%= time do %>
<!-- <% PerfTest::FastComponent.new(self).render_in %> -->
<% end %>

<% PerfTest::FastComponent.new(self).render_in %>

0 comments on commit af02ed5

Please sign in to comment.