aboutsummaryrefslogtreecommitdiffstats
path: root/benchmark
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-26 13:49:35 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-26 13:49:35 +0000
commit84e460b508538436b519e63465b0f7f94a8fc7a4 (patch)
treeb8dbade20037c4b06a8c8c4001187901c9db21f9 /benchmark
parent82f5443b05421b4f5f9f935a507c60b64a9afdd7 (diff)
downloadruby-84e460b508538436b519e63465b0f7f94a8fc7a4.tar.gz
erb.rb: Generate static string with opt_str_uminus
to skip object allocation for static string. We can't always enable frozen_string_literal pragma because we can't freeze string literals embedded by user for backward compatibility. So we need to use fstring for each static string. Since adding ".freeze" to string literals in #content_dump is slow on compiling, I used unary "-" operator instead. benchmark/bm_app_erb_render.rb: Added rendering-only benchmark to test rendering performance on production environment. This benchmark is created to reproduce the behavior on Sinatra (Tilt). Thus it doesn't use ERB#result to skip parsing compiled code. It doesn't use ERB#def_method too to regard `title` and `content` as local variables. If we use #def_method, `title` and `content` needs to be method call. I wanted to avoid it. This patch's benchmark results is: * Before app_erb_render 1.250 app_erb 0.704 * After app_erb_render 1.066 app_erb 0.686 This patch optimizes rendering performance (app_erb_render) without spoiling (total of rendering +) compiling performance (app_erb). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58905 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/bm_app_erb_render.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/benchmark/bm_app_erb_render.rb b/benchmark/bm_app_erb_render.rb
new file mode 100644
index 0000000000..d2929b0553
--- /dev/null
+++ b/benchmark/bm_app_erb_render.rb
@@ -0,0 +1,26 @@
+require 'erb'
+
+data = DATA.read
+max = 1_500_000
+title = "hello world!"
+content = "hello world!\n" * 10
+
+src = "def self.render(title, content); #{ERB.new(data).src}; end"
+mod = Module.new
+mod.instance_eval(src, "(ERB)")
+
+max.times do
+ mod.render(title, content)
+end
+
+__END__
+
+<html>
+ <head> <%= title %> </head>
+ <body>
+ <h1> <%= title %> </h1>
+ <p>
+ <%= content %>
+ </p>
+ </body>
+</html>