Sha256: 145fd2339c92f5b69ce852bc482e8a2efef236bfd089bfbadaca8ec29a2c4915

Contents?: true

Size: 1.51 KB

Versions: 11

Compression:

Stored size: 1.51 KB

Contents

module Benchmark
  module IPS
    class Job
      class StdoutReport
        def initialize
          @last_item = nil
        end

        def start_warming
          $stdout.puts "Warming up --------------------------------------"
        end

        def start_running
          $stdout.puts "Calculating -------------------------------------"
        end

        def warming(label, _warmup)
          $stdout.print rjust(label)
        end

        def warmup_stats(_warmup_time_us, timing)
          case format
          when :human
            $stdout.printf "%s i/100ms\n", Helpers.scale(timing)
          else
            $stdout.printf "%10d i/100ms\n", timing
          end
        end

        alias_method :running, :warming

        def add_report(item, caller)
          $stdout.puts " #{item.body}"
          @last_item = item
        end

        def footer
          return unless @last_item
          footer = @last_item.stats.footer
          $stdout.puts footer.rjust(40) if footer
        end

        private

        # @return [Symbol] format used for benchmarking
        def format
          Benchmark::IPS.options[:format]
        end

        # Add padding to label's right if label's length < 20,
        # Otherwise add a new line and 20 whitespaces.
        # @return [String] Right justified label.
        def rjust(label)
          label = label.to_s
          if label.size > 20
            "#{label}\n#{' ' * 20}"
          else
            label.rjust(20)
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
benchmark-ips-2.11.0 lib/benchmark/ips/job/stdout_report.rb
benchmark-ips-2.10.0 lib/benchmark/ips/job/stdout_report.rb
benchmark-ips-2.9.3 lib/benchmark/ips/job/stdout_report.rb
benchmark-ips-2.9.2 lib/benchmark/ips/job/stdout_report.rb
benchmark-ips-2.9.1 lib/benchmark/ips/job/stdout_report.rb
benchmark-ips-2.9.0 lib/benchmark/ips/job/stdout_report.rb
benchmark-ips-2.8.4 lib/benchmark/ips/job/stdout_report.rb
benchmark-ips-2.8.3 lib/benchmark/ips/job/stdout_report.rb
benchmark-ips-2.8.2 lib/benchmark/ips/job/stdout_report.rb
benchmark-ips-2.8.0 lib/benchmark/ips/job/stdout_report.rb
motion-benchmark-ips-1.1 lib/project/ips/job/stdout_report.rb