class ActiveSupport::Testing::Performance::Benchmarker

Constants

Public Class Methods

new(*args) click to toggle source
# File lib/rails/perftest/active_support/testing/performance.rb, line 156
def initialize(*args)
  super
  @supported = @metric.respond_to?('measure')
end

Public Instance Methods

environment() click to toggle source
# File lib/rails/perftest/active_support/testing/performance.rb, line 176
def environment
  @env ||= [].tap do |env|
    env << "#{$1}.#{$2}" if File.directory?('.git') && `git branch -v` =~ /^\* (\S+)\s+(\S+)/
    env << rails_version if defined?(Rails::VERSION::STRING)
    env << "#{RUBY_ENGINE}-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}"
    env << RUBY_PLATFORM
  end.join(',')
end
record() click to toggle source
# File lib/rails/perftest/active_support/testing/performance.rb, line 168
def record
  avg = @metric.total / full_profile_options[:runs].to_i
  now = Time.now.utc.xmlschema
  with_output_file do |file|
    file.puts "#{avg},#{now},#{environment}"
  end
end
run() click to toggle source
# File lib/rails/perftest/active_support/testing/performance.rb, line 161
def run
  return unless @supported

  full_profile_options[:runs].to_i.times { run_test(@metric, :benchmark) }
  @total = @metric.total
end

Protected Instance Methods

output_filename() click to toggle source
# File lib/rails/perftest/active_support/testing/performance.rb, line 205
def output_filename
  "#{super}.csv"
end
rails_branch() click to toggle source
# File lib/rails/perftest/active_support/testing/performance.rb, line 213
def rails_branch
  if File.directory?('vendor/rails/.git')
    Dir.chdir('vendor/rails') do
      ".#{$1}.#{$2}" if `git branch -v` =~ /^\* (\S+)\s+(\S+)/
    end
  end
end
rails_version() click to toggle source
# File lib/rails/perftest/active_support/testing/performance.rb, line 209
def rails_version
  "rails-#{Rails::VERSION::STRING}#{rails_branch}"
end
with_output_file() { |file| ... } click to toggle source
# File lib/rails/perftest/active_support/testing/performance.rb, line 192
def with_output_file
  fname = output_filename

  if new = !File.exist?(fname)
    FileUtils.mkdir_p(File.dirname(fname))
  end

  File.open(fname, 'ab') do |file|
    file.puts(HEADER) if new
    yield file
  end
end