Class: Tack::Formatters::Profiler
- Inherits:
-
Object
- Object
- Tack::Formatters::Profiler
- Includes:
- Middleware
- Defined in:
- lib/tack/formatters/profiler.rb
Instance Method Summary collapse
-
#initialize(app, args) ⇒ Profiler
constructor
A new instance of Profiler.
- #run_suite(tests) ⇒ Object
- #run_test(file, description) ⇒ Object
Methods included from Middleware
Constructor Details
#initialize(app, args) ⇒ Profiler
Returns a new instance of Profiler.
8 9 10 11 12 |
# File 'lib/tack/formatters/profiler.rb', line 8 def initialize(app, args) @app = app @num_tests = args.fetch(:tests) { 10 } @times = [] end |
Instance Method Details
#run_suite(tests) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tack/formatters/profiler.rb', line 14 def run_suite(tests) returning @app.run_suite(tests) do |results| puts "\n\nTop #{@num_tests} slowest examples:\n" @times = @times.sort_by do |description, time| time end.reverse @times[0..@num_tests-1].each do |description, time| print "%.7f" % time puts " #{description}" end end end |
#run_test(file, description) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/tack/formatters/profiler.rb', line 27 def run_test(file, description) time = Time.now returning @app.run_test(file,description) do @times << [description, Time.now - time] end end |