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.8.0 lib/vedeu/logging/ips.rb
vedeu-0.7.4 lib/vedeu/logging/ips.rb
vedeu-0.7.3 lib/vedeu/logging/ips.rb
vedeu-0.7.2 lib/vedeu/logging/ips.rb
vedeu-0.7.1 lib/vedeu/logging/ips.rb
vedeu-0.7.0 lib/vedeu/logging/ips.rb
vedeu-0.6.71 lib/vedeu/logging/ips.rb
vedeu-0.6.70 lib/vedeu/logging/ips.rb
vedeu-0.6.69 lib/vedeu/logging/ips.rb
vedeu-0.6.68 lib/vedeu/logging/ips.rb
vedeu-0.6.67 lib/vedeu/logging/ips.rb
vedeu-0.6.66 lib/vedeu/logging/ips.rb
vedeu-0.6.65 lib/vedeu/logging/ips.rb
vedeu-0.6.64 lib/vedeu/logging/ips.rb
vedeu-0.6.63 lib/vedeu/logging/ips.rb
vedeu-0.6.62 lib/vedeu/logging/ips.rb
vedeu-0.6.61 lib/vedeu/logging/ips.rb
vedeu-0.6.60 lib/vedeu/logging/ips.rb
vedeu-0.6.59 lib/vedeu/logging/ips.rb
vedeu-0.6.58 lib/vedeu/logging/ips.rb