Skip to content

Commit

Permalink
use benchmarks-ips
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Dec 5, 2014
1 parent a308d5d commit 6f8acb8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ env:
- "TASK=test:sinatra SINATRA=master"
- "TASK=test:sinatra SINATRA=1.3.6"
- "TASK=test:sinatra SINATRA=1.4.5"
- "TASK=bench iterations=10000"
- "TASK=bench slow=1 iterations=1000"
- "TASK=bench"
- "TASK=bench slow=1"

matrix:
exclude:
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ gem 'asciidoctor'
gem 'org-ruby'

if ENV['TASK'] == 'bench'
gem 'benchmark-ips'
gem 'erubis'
gem 'haml'
end
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ end

require 'rake/testtask'

desc 'Run Slim benchmarks! (default parameters slow=false iterations=1000)'
task :bench, :iterations, :slow do
desc 'Run Slim benchmarks! (default parameters slow=false)'
task :bench, :slow do
ruby('benchmarks/run-benchmarks.rb')
end

Expand Down
14 changes: 5 additions & 9 deletions benchmarks/run-benchmarks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
require 'slim'
require 'context'

require 'benchmark'
require 'benchmark/ips'
require 'tilt'
require 'erubis'
require 'erb'
require 'haml'

class SlimBenchmarks
def initialize(slow, iterations)
@iterations = (iterations || 1000).to_i
def initialize(slow)
@benches = []

@erb_code = File.read(File.dirname(__FILE__) + '/view.erb')
Expand Down Expand Up @@ -90,12 +89,9 @@ def init_parsing_benches
end

def run
puts "#{@iterations} Iterations"
Benchmark.bmbm do |x|
Benchmark.ips do |x|
@benches.each do |name, block|
x.report name.to_s do
@iterations.to_i.times { block.call }
end
x.report(name.to_s, &block)
end
end
puts "
Expand Down Expand Up @@ -123,4 +119,4 @@ def bench(name, &block)
end
end

SlimBenchmarks.new(ENV['slow'], ENV['iterations']).run
SlimBenchmarks.new(ENV['slow']).run

0 comments on commit 6f8acb8

Please sign in to comment.