Sha256: 527c6517e0c175af9d4922fa98aeb3becb4f760de88cbd70a8069e867e307b07

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

require_relative "performance_helper"
require "slim"

configure do
  set :views, __dir__
end
Nyara::View.init
$page_tilt = Tilt.new __dir__ + '/page.slim'
$layout_tilt = Tilt.new __dir__ + '/layout.slim'

class MyRenderable
  def initialize items
    @title = "layout_render"
    @items = items
  end
  include Nyara::Renderable

  def send_chunk s
    @res ||= []
    @res << s
  end

  def nyara_render
    view = Nyara::View.new self, 'page.slim', ['layout.slim', 'layout.slim'], {items: @items}, {}
    Fiber.new{ view.render }.resume
  end

  def tilt_render
    Fiber.new{}.resume # XXX simulate the overhead of every request
    $layout_tilt.render self do
      $layout_tilt.render self do
        $page_tilt.render self, items: @items
      end
    end
  end
end

# prepare data
Item = Struct.new :name, :price
items = 10.times.map do |i|
  Item.new "name#{i}", i
end

# precompile
MyRenderable.new(items).nyara_render
MyRenderable.new(items).tilt_render

GC.disable

nyara = bench(1000){ MyRenderable.new(items).nyara_render }
tilt = bench(1000){ MyRenderable.new(items).tilt_render }
dump nyara: nyara, tilt: tilt

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
nyara-0.0.1.pre.9 spec/performance/layout_render.rb
nyara-0.0.1.pre.8 spec/performance/layout_render.rb
nyara-0.0.1.pre.6 spec/performance/layout_render.rb
nyara-0.0.1.pre.5 spec/performance/layout_render.rb
nyara-0.0.1.pre.4 spec/performance/layout_render.rb
nyara-0.0.1.pre.3 spec/performance/layout_render.rb