File: benchmark.rb

package info (click to toggle)
ruby-hamlit 2.15.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,996 kB
  • sloc: ruby: 10,548; ansic: 536; sh: 23; makefile: 8
file content (25 lines) | stat: -rw-r--r-- 951 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Original: https://github.com/amatsuda/string_template/blob/master/benchmark.rb
require 'benchmark_driver'

Benchmark.driver(repeat_count: 8) do |x|
  x.prelude %{
    require 'rails'
    require 'action_view'
    require 'string_template'
    StringTemplate::Railtie.run_initializers
    require 'hamlit'
    Hamlit::Railtie.run_initializers
    Hamlit::RailsTemplate.set_options(escape_html: false, generator: Temple::Generators::ArrayBuffer)
    require 'action_view/base'

    (view = Class.new(ActionView::Base).new(ActionView::LookupContext.new(''))).instance_variable_set(:@world, 'world!')

    # compile template
    hello = 'benchmark/dynamic_merger/hello'
    view.render(template: hello, handlers: 'string')
    view.render(template: hello, handlers: 'haml')
  }
  x.report 'string', %{ view.render(template: hello, handlers: 'string') }
  x.report 'hamlit', %{ view.render(template: hello, handlers: 'haml') }
  x.loop_count 100_000
end