diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-12-09 11:17:11 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-12-09 11:17:11 -0800 |
commit | e8c4939fb3366472021c1af1331bfdfe5d7a5d75 (patch) | |
tree | 0f1d9e20cb5a0e30820f6ccc8e9dd735e3273f1f /actionpack/lib/action_controller | |
parent | c3fe6ebbfaedff8d6dd8f590bdd237fac174faac (diff) | |
download | rails-e8c4939fb3366472021c1af1331bfdfe5d7a5d75.tar.gz rails-e8c4939fb3366472021c1af1331bfdfe5d7a5d75.tar.bz2 rails-e8c4939fb3366472021c1af1331bfdfe5d7a5d75.zip |
Benchmark.ms
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/benchmarking.rb | 16 | ||||
-rw-r--r-- | actionpack/lib/action_controller/request_profiler.rb | 12 |
2 files changed, 14 insertions, 14 deletions
diff --git a/actionpack/lib/action_controller/benchmarking.rb b/actionpack/lib/action_controller/benchmarking.rb index fa572ebf3d..732f774fbc 100644 --- a/actionpack/lib/action_controller/benchmarking.rb +++ b/actionpack/lib/action_controller/benchmarking.rb @@ -23,8 +23,8 @@ module ActionController #:nodoc: def benchmark(title, log_level = Logger::DEBUG, use_silence = true) if logger && logger.level == log_level result = nil - seconds = Benchmark.realtime { result = use_silence ? silence { yield } : yield } - logger.add(log_level, "#{title} (#{('%.1f' % (seconds * 1000))}ms)") + ms = Benchmark.ms { result = use_silence ? silence { yield } : yield } + logger.add(log_level, "#{title} (#{('%.1f' % ms)}ms)") result else yield @@ -48,7 +48,7 @@ module ActionController #:nodoc: end render_output = nil - @view_runtime = Benchmark::realtime { render_output = render_without_benchmark(options, extra_options, &block) } + @view_runtime = Benchmark.ms { render_output = render_without_benchmark(options, extra_options, &block) } if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? @db_rt_before_render = db_runtime @@ -65,11 +65,11 @@ module ActionController #:nodoc: private def perform_action_with_benchmark if logger - seconds = [ Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001 ].max + ms = [Benchmark.ms { perform_action_without_benchmark }, 0.01].max logging_view = defined?(@view_runtime) logging_active_record = Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? - log_message = "Completed in #{sprintf("%.0f", seconds * 1000)}ms" + log_message = 'Completed in %.0fms' % ms if logging_view || logging_active_record log_message << " (" @@ -87,21 +87,21 @@ module ActionController #:nodoc: log_message << " [#{complete_request_uri rescue "unknown"}]" logger.info(log_message) - response.headers["X-Runtime"] = "#{sprintf("%.0f", seconds * 1000)}ms" + response.headers["X-Runtime"] = "%.0f" % ms else perform_action_without_benchmark end end def view_runtime - "View: %.0f" % (@view_runtime * 1000) + "View: %.0f" % @view_runtime end def active_record_runtime db_runtime = ActiveRecord::Base.connection.reset_runtime db_runtime += @db_rt_before_render if @db_rt_before_render db_runtime += @db_rt_after_render if @db_rt_after_render - "DB: %.0f" % (db_runtime * 1000) + "DB: %.0f" % db_runtime end end end diff --git a/actionpack/lib/action_controller/request_profiler.rb b/actionpack/lib/action_controller/request_profiler.rb index 70bb77e7ac..80cd55334f 100644 --- a/actionpack/lib/action_controller/request_profiler.rb +++ b/actionpack/lib/action_controller/request_profiler.rb @@ -20,7 +20,7 @@ module ActionController @quiet = true print ' ' - result = Benchmark.realtime do + ms = Benchmark.ms do n.times do |i| run(profiling) print_progress(i) @@ -28,7 +28,7 @@ module ActionController end puts - result + ms ensure @quiet = false end @@ -88,7 +88,7 @@ module ActionController puts 'Warming up once' elapsed = warmup(sandbox) - puts '%.2f sec, %d requests, %d req/sec' % [elapsed, sandbox.request_count, sandbox.request_count / elapsed] + puts '%.0f ms, %d requests, %d req/sec' % [elapsed, sandbox.request_count, 1000 * sandbox.request_count / elapsed] puts "\n#{options[:benchmark] ? 'Benchmarking' : 'Profiling'} #{options[:n]}x" options[:benchmark] ? benchmark(sandbox) : profile(sandbox) @@ -106,13 +106,13 @@ module ActionController def benchmark(sandbox, profiling = false) sandbox.request_count = 0 - elapsed = sandbox.benchmark(options[:n], profiling).to_f + elapsed = sandbox.benchmark(options[:n], profiling) count = sandbox.request_count.to_i - puts '%.2f sec, %d requests, %d req/sec' % [elapsed, count, count / elapsed] + puts '%.0f ms, %d requests, %d req/sec' % [elapsed, count, 1000 * count / elapsed] end def warmup(sandbox) - Benchmark.realtime { sandbox.run(false) } + Benchmark.ms { sandbox.run(false) } end def default_options |