From af02ed5d27e988f4ef30fb80f90357725bc9ebd3 Mon Sep 17 00:00:00 2001 From: Nick Giancola Date: Sat, 15 May 2021 08:43:06 -0700 Subject: [PATCH] playing around with a component that has no Rails/AV dependency --- .../components/perf_test/fast_component.rb | 25 +++++++++++++++++++ .../app/controllers/perf_test_controller.rb | 2 +- spec/dummy/app/views/perf_test/index.html.erb | 16 ++++++++++-- 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 spec/dummy/app/components/perf_test/fast_component.rb diff --git a/spec/dummy/app/components/perf_test/fast_component.rb b/spec/dummy/app/components/perf_test/fast_component.rb new file mode 100644 index 0000000..816d233 --- /dev/null +++ b/spec/dummy/app/components/perf_test/fast_component.rb @@ -0,0 +1,25 @@ +class PerfTest::FastComponent # < Rbexy::Component + # include ActionView::Context + # TEMPLATE = "@output_buffer.safe_concat('

Hello component

'.freeze);@output_buffer.to_s;".freeze + + def initialize(view_context) + # @compiled = Rbexy.compile(Rbexy::Template.new("

Hello component

")) + # @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) + # "

Hello component

" + # tag.h2 "Hello component" + end + + def template + @output_buffer.safe_concat('

Hello component

'.freeze);@output_buffer.to_s; + end +end diff --git a/spec/dummy/app/controllers/perf_test_controller.rb b/spec/dummy/app/controllers/perf_test_controller.rb index 936262a..13ced4b 100644 --- a/spec/dummy/app/controllers/perf_test_controller.rb +++ b/spec/dummy/app/controllers/perf_test_controller.rb @@ -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) "
Avg time (ms): #{avg_duration}
".html_safe end diff --git a/spec/dummy/app/views/perf_test/index.html.erb b/spec/dummy/app/views/perf_test/index.html.erb index 9105e8b..701dd84 100644 --- a/spec/dummy/app/views/perf_test/index.html.erb +++ b/spec/dummy/app/views/perf_test/index.html.erb @@ -5,12 +5,24 @@ <% render "simple_partial" %> <% end %> -

Rbexy component w/ template

+

Inline HTML

<%= time do %> - <% PerfTest::SimpleComponent.new(self).render_in %> + <% end %>

Rbexy component w/ call

<%= time do %> <% PerfTest::CallComponent.new(self).render_in %> <% end %> + +

Rbexy::Component

+<%= time do %> + +<% end %> + +

Rbexy::FastComponent

+<%= time do %> + +<% end %> + +<% PerfTest::FastComponent.new(self).render_in %>