Module: TheForce::Timer
- Defined in:
- lib/the_force/timer.rb
Class Method Summary collapse
- .report_timers ⇒ Object
-
.timer(*args) ⇒ Object
CRZ - totally not thread coherent, but still useful - I wanted to allow you to pass in a symbol which was the method to time…but when I send(symbol) from inside this module, the method loses its binding.
Instance Method Summary collapse
- #report_timers(*args) ⇒ Object
-
#timer(*args, &b) ⇒ Object
CRZ - for mixin; expects just a symbol and list of args - helps solve passing symbol problem CRZ - rewrite with module_function? and move send()‘ing into self.timer as well…
Class Method Details
.report_timers ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/the_force/timer.rb', line 44 def self.report_timers puts puts "-- TIMER REPORT IN ORDER OF timer METHOD *FINISHING*, NOT STARTING --" @timers.each do |x| puts "#{' ' * x[2]}#{x[0].to_s.ljust(50-(2*x[2]), " ")} : #{seconds_to_time(x[1])}" end puts end |
.timer(*args) ⇒ Object
CRZ - totally not thread coherent, but still useful
- I wanted to allow you to pass in a symbol which was the method to time...but when I send(symbol) from inside this module,
the method loses its binding. for example, a method in another class which you time now wouldnt havent access to its
instance variables...
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/the_force/timer.rb', line 30 def self.timer(*args) name = args.shift if args.length > 0 puts "TIMER #{name || ""} starting..." @timer_depth += 1 start_time = Time.now yield end_time = Time.now @timer_depth -= 1 puts "TIMER #{name || ""} ended: #{seconds_to_time(end_time - start_time)} elapsed" @timers << [name || "", (end_time - start_time), @timer_depth] end |
Instance Method Details
#report_timers(*args) ⇒ Object
24 |
# File 'lib/the_force/timer.rb', line 24 def report_timers(*args); Force::Timer.report_timers(*args); end |
#timer(*args, &b) ⇒ Object
CRZ - for mixin; expects just a symbol and list of args
- helps solve passing symbol problem
CRZ - rewrite with module_function? and move send()‘ing into self.timer as well…
15 16 17 18 19 20 21 22 23 |
# File 'lib/the_force/timer.rb', line 15 def timer(*args, &b); if block_given? Force::Timer.timer(*args, &b) else Force::Timer.timer args[0] do send(args.shift, *args) end end end |