Class: ActiveSupport::Testing::Performance::Benchmarker

Inherits:
Performer
  • Object
show all
Defined in:
lib/rails/perftest/active_support/testing/performance.rb

Instance Method Summary collapse

Methods inherited from Performer

#report

Constructor Details

#initialize(*args) ⇒ Benchmarker

Returns a new instance of Benchmarker.



156
157
158
159
# File 'lib/rails/perftest/active_support/testing/performance.rb', line 156

def initialize(*args)
  super
  @supported = @metric.respond_to?('measure')
end

Instance Method Details

#environmentObject



176
177
178
179
180
181
182
183
# 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

#recordObject



168
169
170
171
172
173
174
# 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

#runObject



161
162
163
164
165
166
# 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