Class: Benchmark::IPSJob::Entry
- Inherits:
-
Object
- Object
- Benchmark::IPSJob::Entry
- Defined in:
- lib/benchmark/ips.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.
Constructor Details
#initialize(label, action) ⇒ Entry
Returns a new instance of Entry.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/benchmark/ips.rb', line 50 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.
74 75 76 |
# File 'lib/benchmark/ips.rb', line 74 def action @action end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
74 75 76 |
# File 'lib/benchmark/ips.rb', line 74 def label @label end |
Instance Method Details
#as_action? ⇒ Boolean
76 77 78 |
# File 'lib/benchmark/ips.rb', line 76 def as_action? @as_action end |
#call_times(times) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/benchmark/ips.rb', line 80 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
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/benchmark/ips.rb', line 92 def compile(str) m = (class << self; self; end) code = <<-CODE def call_times(__total); __i = 0 while __i < __total #{str}; __i += 1 end end CODE m.class_eval code end |