Class: Benchmark::IPS::Job::Entry
- Inherits:
-
Object
- Object
- Benchmark::IPS::Job::Entry
- Defined in:
- lib/benchmark/ips/job.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
- #as_action? ⇒ Boolean
- #call_times(times) ⇒ Object
- #compile(str) ⇒ Object
-
#initialize(label, action) ⇒ Entry
constructor
A new instance of Entry.
- #label_rjust ⇒ Object
Constructor Details
#initialize(label, action) ⇒ Entry
Returns a new instance of Entry.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/benchmark/ips/job.rb', line 9 def initialize(label, action) @label = label if action.kind_of? String compile action @action = self @as_action = true else unless action.respond_to? :call raise ArgumentError, "invalid action, must respond to #call" end @action = action if action.respond_to? :arity and action.arity > 0 @call_loop = true else @call_loop = false end @as_action = false end end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
33 34 35 |
# File 'lib/benchmark/ips/job.rb', line 33 def action @action end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
33 34 35 |
# File 'lib/benchmark/ips/job.rb', line 33 def label @label end |
Instance Method Details
#as_action? ⇒ Boolean
43 44 45 |
# File 'lib/benchmark/ips/job.rb', line 43 def as_action? @as_action end |
#call_times(times) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/benchmark/ips/job.rb', line 47 def call_times(times) return @action.call(times) if @call_loop act = @action i = 0 while i < times act.call i += 1 end end |
#compile(str) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/benchmark/ips/job.rb', line 59 def compile(str) m = (class << self; self; end) code = " def call_times(__total);\n __i = 0\n while __i < __total\n \#{str};\n __i += 1\n end\n end\n CODE\n m.class_eval code\nend\n" |
#label_rjust ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/benchmark/ips/job.rb', line 35 def label_rjust if @label.size > 20 "#{@label}\n#{' ' * 20}" else @label.rjust(20) end end |