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

Inherits:
Performer show all
Defined in:
activesupport/lib/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.



180
181
182
183
# File 'activesupport/lib/active_support/testing/performance.rb', line 180

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

Instance Method Details

#environmentObject



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'activesupport/lib/active_support/testing/performance.rb', line 200

def environment
  unless defined? @env
    app = "#{$1}.#{$2}" if File.directory?('.git') && `git branch -v` =~ /^\* (\S+)\s+(\S+)/

    rails = Rails::VERSION::STRING
    if File.directory?('vendor/rails/.git')
      Dir.chdir('vendor/rails') do
        rails += ".#{$1}.#{$2}" if `git branch -v` =~ /^\* (\S+)\s+(\S+)/
      end
    end

    ruby = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
    ruby += "-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}"

    @env = [app, rails, ruby, RUBY_PLATFORM] * ','
  end

  @env
end

#recordObject



192
193
194
195
196
197
198
# File 'activesupport/lib/active_support/testing/performance.rb', line 192

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



185
186
187
188
189
190
# File 'activesupport/lib/active_support/testing/performance.rb', line 185

def run
  return unless @supported

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