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.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/benchmark/ips.rb', line 52 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.
76 77 78 |
# File 'lib/benchmark/ips.rb', line 76 def action @action end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
76 77 78 |
# File 'lib/benchmark/ips.rb', line 76 def label @label end |
Instance Method Details
#as_action? ⇒ Boolean
78 79 80 |
# File 'lib/benchmark/ips.rb', line 78 def as_action? @as_action end |
#call_times(times) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/benchmark/ips.rb', line 82 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
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/benchmark/ips.rb', line 94 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 |