module Benchmark::Ipsa

Constants

VERSION

Public Instance Methods

allocations(x) click to toggle source
# File lib/benchmark/ipsa.rb, line 15
def allocations(x)
  return unless RUBY_VERSION >= "2.1.0" # MemoryProfiler needs 2.1. degrade to just ips

  puts "Allocations -------------------------------------"
  x.list.each do |entry|
    report = MemoryProfiler.report(&entry.action)
    $stdout.print(rjust(entry.label))
    $stdout.printf("%10s  alloc/ret %10s  strings/ret\n",
                   "#{report.total_allocated}/#{report.total_retained}",
    "#{report.strings_allocated.count}/#{report.strings_retained.count}")
  end
end
ipsa(*args, &block) click to toggle source
# File lib/benchmark/ipsa.rb, line 7
def ipsa(*args, &block)
  Benchmark.ips(*args){ |x|
    block.call(x)
    allocations(x)
  }

end
rjust(label) click to toggle source
# File lib/benchmark/ipsa.rb, line 28
def rjust(label) #stolen from benchmark-ips
  label = label.to_s
  if label.size > 20
    "#{label}\n#{' ' * 20}"
  else
    label.rjust(20)
  end
end