1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Detect performance regression with CI

This commit is contained in:
Takashi Kokubun 2015-03-28 14:21:48 +09:00
parent e8269b6c66
commit 2b99ac523b
2 changed files with 20 additions and 5 deletions

View file

@ -2,7 +2,7 @@ require 'bundler/gem_tasks'
desc 'Run benchmarks' desc 'Run benchmarks'
task :bench do task :bench do
system('bundle exec ruby benchmarks/benchmark.rb') exit system('bundle exec ruby benchmarks/benchmark.rb')
end end
desc 'Run RSpec code examples' desc 'Run RSpec code examples'

View file

@ -48,10 +48,10 @@ class Benchmarks
def run_hamlit; #{Hamlit::Engine.new.call @haml_code}; end def run_hamlit; #{Hamlit::Engine.new.call @haml_code}; end
} }
bench('erubis') { context.run_erubis }
bench('slim') { context.run_slim_ugly }
bench('fast_haml') { context.run_fast_haml }
bench('hamlit') { context.run_hamlit } bench('hamlit') { context.run_hamlit }
bench('erubis') { context.run_erubis }
bench('fast_haml') { context.run_fast_haml }
bench('slim') { context.run_slim_ugly }
if ENV['ALL'] if ENV['ALL']
bench('tenjin') { context.run_tenjin } bench('tenjin') { context.run_tenjin }
@ -63,18 +63,33 @@ class Benchmarks
end end
def run def run
Benchmark.ips do |x| result = Benchmark.ips do |x|
x.config(time: @time, warmup: 2) x.config(time: @time, warmup: 2)
@benches.each do |name, block| @benches.each do |name, block|
x.report(name, &block) x.report(name, &block)
end end
x.compare! x.compare!
end end
assert_fastest(result)
end end
def bench(name, &block) def bench(name, &block)
@benches.push([name, block]) @benches.push([name, block])
end end
def assert_fastest(result)
hamlit = result.entries.first
rival = result.entries[1..-1].max_by(&:ips)
if hamlit.ips < rival.ips
fatal "Hamlit is slower than #{rival.label}"
end
end
def fatal(message)
puts "\e[31m#{message}\e[0m"
exit 1
end
end end
time = (ENV['TIME'] || 5).to_i time = (ENV['TIME'] || 5).to_i