Sha256: 948e536006bdaf765d2c9438eef35e5c254bb2a1fe93a5e2127cef37b36cd5e9

Contents?: true

Size: 1000 Bytes

Versions: 74

Compression:

Stored size: 1000 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

74 entries across 74 versions & 1 rubygems

Version Path
rroonga-4.0.5-x64-mingw32 benchmark/common.rb
rroonga-4.0.5-x86-mingw32 benchmark/common.rb
rroonga-4.0.5 benchmark/common.rb
rroonga-4.0.4-x86-mingw32 benchmark/common.rb
rroonga-4.0.4-x64-mingw32 benchmark/common.rb
rroonga-4.0.4 benchmark/common.rb
rroonga-4.0.3-x86-mingw32 benchmark/common.rb
rroonga-4.0.3-x64-mingw32 benchmark/common.rb
rroonga-4.0.3 benchmark/common.rb
rroonga-4.0.2-x64-mingw32 benchmark/common.rb
rroonga-4.0.2-x86-mingw32 benchmark/common.rb
rroonga-4.0.2 benchmark/common.rb
rroonga-4.0.1-x86-mingw32 benchmark/common.rb
rroonga-4.0.1-x64-mingw32 benchmark/common.rb
rroonga-4.0.1 benchmark/common.rb
rroonga-4.0.0-x64-mingw32 benchmark/common.rb
rroonga-4.0.0-x86-mingw32 benchmark/common.rb
rroonga-4.0.0 benchmark/common.rb
rroonga-3.1.2-x64-mingw32 benchmark/common.rb
rroonga-3.1.2-x86-mingw32 benchmark/common.rb