Sha256: 4b80810d6ba291a5da6dc1c275beb3626dbd8d63ecc85b5e6ea70c2eefc8248c

Contents?: true

Size: 1.33 KB

Versions: 28

Compression:

Stored size: 1.33 KB

Contents

require 'benchmark/ips'

module Vedeu

  module Logging

    module Debug

      # Provide wrapper for 'benchmark-ips' gem.
      #
      class IPS

        attr_accessor :samples
        attr_accessor :benchmark

        # Returns a new instance of Vedeu::Logging::Debug::IPS.
        #
        # @return [Vedeu::Logging::Debug::IPS]
        def initialize
          @old_stdout = $stdout
          $stdout     = StringIO.new
          @samples    = {}
          @benchmark  = Benchmark::IPS::Job.new
          @count      = 0
        end

        # @param label [String]
        # @return [void]
        def add_item(label = '', &blk)
          samples[label] = blk
          @count += 1

          benchmark.item(label, &blk)
        end

        # @return [void]
        def execute!
          benchmark.compare!
          benchmark.run_warmup
          benchmark.run

          $stdout.sync = true
          benchmark.run_comparison
          benchmark.full_report

          Vedeu.log(type: :debug, message: "IPS:\n#{$stdout.string}".freeze)
          $stdout = @old_stdout

          Vedeu.log(type: :debug, message: "Running: #{key}".freeze)
          samples[key].call
        end

        private

        # @return [void]
        def key
          @key ||= samples.keys.sample
        end

      end # IPS

    end # Debug

  end # Logging

end # Vedeu

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
vedeu-0.6.57 lib/vedeu/logging/ips.rb
vedeu-0.6.56 lib/vedeu/logging/ips.rb
vedeu-0.6.54 lib/vedeu/logging/ips.rb
vedeu-0.6.53 lib/vedeu/logging/ips.rb
vedeu-0.6.52 lib/vedeu/logging/ips.rb
vedeu-0.6.51 lib/vedeu/logging/ips.rb
vedeu-0.6.50 lib/vedeu/logging/ips.rb
vedeu-0.6.49 lib/vedeu/logging/ips.rb