Sha256: a7fc217812bbc4dd3c3db36acae1a297c01c5fc7a8a930c735916b1d3218f9f4

Contents?: true

Size: 997 Bytes

Versions: 85

Compression:

Stored size: 997 Bytes

Contents

require "benchmark"
require "tempfile"

def memory_usage
  status = `cat /proc/#{$$}/status`
  lines = status.split("\n")
  lines.each do |line|
    if line =~ /^VmRSS:/
      line.gsub!(/.*:\s*(\d+).*/, '\1')
      return line.to_i / 1024.0
    end
  end
  return -1
end

@items = []

def item(label, &block)
  @items << [label, block]
end

def report(index=0)
  width = @items.collect do |label, _|
    label.length
  end.max

  label, block = @items[index]
  if label.nil?
    puts "unavailable report ID: #{index}"
    puts "available IDs:"
    @items.each_with_index do |(label, block), i|
      puts "#{i}: #{label}"
    end
    exit 1
  end

  if index.zero?
    puts(" " * (width - 1) + Benchmark::Tms::CAPTION.rstrip + "memory".rjust(11))
  end
  # GC.disable
  before = memory_usage
  result = Benchmark.measure(&block)
  # GC.enable
  GC.start
  size = memory_usage - before

  formatted_size = "%7.3f" % size
  puts "#{label.ljust(width)} #{result.to_s.strip} #{formatted_size}MB"
end

Version data entries

85 entries across 85 versions & 1 rubygems

Version Path
rroonga-6.0.4-x86-mingw32 benchmark/common.rb
rroonga-6.0.4-x64-mingw32 benchmark/common.rb
rroonga-6.0.4 benchmark/common.rb
rroonga-6.0.2-x64-mingw32 benchmark/common.rb
rroonga-6.0.2-x86-mingw32 benchmark/common.rb
rroonga-6.0.2 benchmark/common.rb
rroonga-6.0.0-x64-mingw32 benchmark/common.rb
rroonga-6.0.0-x86-mingw32 benchmark/common.rb
rroonga-6.0.0 benchmark/common.rb
rroonga-5.1.1-x86-mingw32 benchmark/common.rb
rroonga-5.1.1-x64-mingw32 benchmark/common.rb
rroonga-5.1.1 benchmark/common.rb
rroonga-5.0.9-x86-mingw32 benchmark/common.rb
rroonga-5.0.9-x64-mingw32 benchmark/common.rb
rroonga-5.0.9 benchmark/common.rb
rroonga-5.0.8-x86-mingw32 benchmark/common.rb
rroonga-5.0.8-x64-mingw32 benchmark/common.rb
rroonga-5.0.8 benchmark/common.rb
rroonga-5.0.5-x86-mingw32 benchmark/common.rb
rroonga-5.0.5-x64-mingw32 benchmark/common.rb