Class: Benchmark::IPS::Job::Entry
- Inherits:
 - 
      Object
      
        
- Object
 - Benchmark::IPS::Job::Entry
 
 
- Defined in:
 - lib/benchmark/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.
 - #compile_block ⇒ Object
 - #compile_block_with_manual_loop ⇒ Object
 - 
  
    
      #compile_string(str)  ⇒ Symbol 
    
    
  
  
  
  
  
  
  
  
  
    
Compile code into
call_timesmethod. - 
  
    
      #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/benchmark/ips/job/entry.rb', line 11 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  | 
  
Instance Attribute Details
#action ⇒ String, Proc (readonly)
The benchmarking action.
      41 42 43  | 
    
      # File 'lib/benchmark/ips/job/entry.rb', line 41 def action @action end  | 
  
#label ⇒ #to_s (readonly)
The label of benchmarking action.
      37 38 39  | 
    
      # File 'lib/benchmark/ips/job/entry.rb', line 37 def label @label end  | 
  
Instance Method Details
#call_times(times) ⇒ Integer
Call action by given times.
      46 47 48  | 
    
      # File 'lib/benchmark/ips/job/entry.rb', line 46 def call_times(times) raise '#call_times should be redefined per Benchmark::IPS::Job::Entry instance' end  | 
  
#compile_block ⇒ Object
      50 51 52 53 54 55 56 57 58 59 60 61 62 63 64  | 
    
      # File 'lib/benchmark/ips/job/entry.rb', line 50 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  | 
  
#compile_block_with_manual_loop ⇒ Object
      66 67 68 69 70 71 72 73 74  | 
    
      # File 'lib/benchmark/ips/job/entry.rb', line 66 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  | 
  
#compile_string(str) ⇒ Symbol
Compile code into call_times method.
      79 80 81 82 83 84 85 86 87 88 89 90 91  | 
    
      # File 'lib/benchmark/ips/job/entry.rb', line 79 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  |