Class: Benchmark::IPS::Job::Entry
- Inherits:
-
Object
- Object
- Benchmark::IPS::Job::Entry
- Defined in:
- lib/project/ips/job/entry.rb
Overview
Entries in Benchmark Jobs.
Instance Attribute Summary collapse
-
#action ⇒ String, Proc
readonly
The benchmarking action.
-
#label ⇒ #to_s
readonly
The label of benchmarking action.
Instance Method Summary collapse
-
#call_times(times) ⇒ Integer
Call action by given times, return if @call_loop is present.
-
#compile(str) ⇒ Symbol
Compile code into
call_times
method. -
#initialize(label, action) ⇒ Entry
constructor
Instantiate the Benchmark::IPS::Job::Entry.
Constructor Details
#initialize(label, action) ⇒ Entry
Instantiate the Benchmark::IPS::Job::Entry.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/project/ips/job/entry.rb', line 11 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 ⇒ String, Proc (readonly)
The benchmarking action.
41 42 43 |
# File 'lib/project/ips/job/entry.rb', line 41 def action @action end |
#label ⇒ #to_s (readonly)
The label of benchmarking action.
37 38 39 |
# File 'lib/project/ips/job/entry.rb', line 37 def label @label end |
Instance Method Details
#call_times(times) ⇒ Integer
Call action by given times, return if @call_loop is present.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/project/ips/job/entry.rb', line 46 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) ⇒ Symbol
Compile code into call_times
method.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/project/ips/job/entry.rb', line 61 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 |