hrb/benchmark/simple.rb

78 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require "bundler/inline"
gemfile ENV.key?("INSTALL_GEMS") do
source "https://rubygems.org"
gem "benchmark-ips"
gem "benchmark-memory"
gem "erubi"
gem "markaby"
gem "pry"
gem "rubyoshka"
gem "slim"
gem "tilt"
gem "hrb", path: "../"
end
def render(extension)
Tilt.new(File.join(__dir__, "templates", "simple.#{extension}")).render(nil, created: "2019-06-17", numbers: (1..100))
end
def render_rubyoshka
Rubyoshka.new do
with(created: "2019-06-17", numbers: (1..100)) do
instance_eval(File.read(File.join(__dir__, "templates", "simple.html.rb")))
end
end.render
end
erubi_src = Erubi::Engine.new(File.join(__dir__, "templates", "simple.erb")).src
numbers = (1..100)
created = "2019-06-17"
require "benchmark/ips"
Benchmark.ips do |x|
x.report("Erubi:") do
render("erb")
end
x.report("Erubi fast:") do
eval(erubi_src)
end
x.report("Rubyoshka:") do
render_rubyoshka
end
x.report("Hrb:") do
render("html.rb")
end
x.compare!
end
if ENV.key?("MEMORY")
require "benchmark/memory"
Benchmark.memory do |x|
x.report("Erubi:") do
render("erb")
end
x.report("Erubi fast:") do
eval(erubi_src)
end
x.report("Hrb:") do
render("html.rb")
end
x.report("Rubyoshka:") do
render_rubyoshka
end
x.compare!
end
end