Sha256: 893042b374349f9ce6cf1e530edd59982f1a3e9658f1454778f8889ec4971cc6

Contents?: true

Size: 1001 Bytes

Versions: 44

Compression:

Stored size: 1001 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(14))
  end
  # GC.disable
  before = memory_usage
  result = Benchmark.measure(&block)
  # GC.enable
  GC.start
  size = memory_usage - before

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

Version data entries

44 entries across 44 versions & 2 rubygems

Version Path
rroonga-1.3.0-x86-mingw32 benchmark/common.rb
rroonga-1.3.0 benchmark/common.rb
rroonga-1.2.9 benchmark/common.rb
rroonga-1.2.8 benchmark/common.rb
rroonga-1.2.7-x86-mswin32 benchmark/common.rb
rroonga-1.2.7-x86-mingw32 benchmark/common.rb
rroonga-1.2.7 benchmark/common.rb
rroonga-1.2.6 benchmark/common.rb
rroonga-1.2.5-x86-mingw32 benchmark/common.rb
rroonga-1.2.5 benchmark/common.rb
rroonga-1.2.4 benchmark/common.rb
rroonga-1.2.3 benchmark/common.rb
rroonga-1.2.2 benchmark/common.rb
rroonga-1.2.1 benchmark/common.rb
rroonga-1.2.0 benchmark/common.rb
rroonga-1.1.0-x86-mingw32 benchmark/common.rb
rroonga-1.1.0 benchmark/common.rb
rroonga-1.0.9 benchmark/common.rb
rroonga-1.0.8 benchmark/common.rb
rroonga-1.0.7 benchmark/common.rb