class Benchmark::IPS::Job::Entry
Entries in Benchmark Jobs.
def call_times(times)
-
(Integer)
- Number of times the +@action+ has been called.
Parameters:
-
times
(Integer
) -- Times to call +@action+.
def call_times(times) raise '#call_times should be redefined per Benchmark::IPS::Job::Entry instance' end
def compile_block
def compile_block m = (class << self; self; end) code = <<-CODE def call_times(times) act = @action i = 0 while i < times act.call i += 1 end end CODE m.class_eval code end
def compile_block_with_manual_loop
def compile_block_with_manual_loop m = (class << self; self; end) code = <<-CODE def call_times(times) @action.call(times) end CODE m.class_eval code end
def compile_string(str)
-
(Symbol)
- :call_times.
Parameters:
-
str
(String
) -- Code to be compiled.
def compile_string(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
def initialize(label, action)
-
(ArgumentError)
- Raises when action is not String or not responding to +call+.
Parameters:
-
action
(String, Proc
) -- Code to be benchmarked. -
label
(#to_s
) -- Label of Benchmarked code.
def initialize(label, action) @label = label # We define #call_times on the singleton class of each Entry instance. # That way, there is no polymorphism for `@action.call` inside #call_times. if action.kind_of? String compile_string action @action = self 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 compile_block_with_manual_loop else compile_block end end end