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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#!/usr/bin/env ruby
require 'bundler/setup'
require 'hamlit'
require 'lineprof'
require 'tempfile'
require 'thor'
class CLI < Thor
desc 'render HAML', 'Benchmark render'
def render(file)
haml = File.read(file)
compiled = Hamlit::Engine.new.call(haml)
code = [
'require "lineprof"',
'require "hamlit"',
'Lineprof.profile(/./) do',
'100.times do',
compiled,
'end',
'end',
].join("\n")
file = Tempfile.create('compiled')
file.write(code)
file.close
system("bundle exec ruby #{file.path}")
end
desc 'compile HAML', 'Benchmark compile'
def compile(file)
haml = File.read(file)
Lineprof.profile(/./) do
100.times { Hamlit::Engine.new.call(haml) }
end
end
private
def method_missing(*args)
return super if args.length > 1
render(args.first.to_s)
end
end
CLI.start
|