# class Benchmark::IPSJob::Entry

### Attributes

action[R]
label[R]

### Public Class Methods

new(label, action) click to toggle source

    # 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

### Public Instance Methods

as_action?() click to toggle source

    # File lib/benchmark/ips.rb, line 76
    def as_action?
      @as_action
    end

call_times(times) click to toggle source

    # 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) click to toggle source

    # 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