Notes from Sam Saffron's 'Measuring Ruby' talk at GoGaRuCo 2013

ruby

Posted

I just watched Sam Saffron's "Measuring Ruby" talk at Golden Gate Ruby Conference 2013. I wanted to take a few notes, since I don't know a lot about performance tuning, and thought I'd publish them rather than keep them to myself. These are pretty unpolished; obviously, watch the talk if you want more.

def print_duration(name)
  start = Time.now
  result = yield
  total = (Time.now - start) * 1000
  puts “#{name}: #{total.to_i)ms”
  result
end

alias_method :some_method_old, :some_method
def some_method(*args, &blk)
  print_duration(“some description”) do
    some_method(*args, &blk)
  end
end

You can find them with:

exceptions = []
TracePoint.new(:raise) do |tp
  exceptions << tp.raised_exception
end
trace.enable

Wrapup

  1. Audit memory usage using memory_profiler
  2. Run rack_mini_profiler to integrate performance metrics into dev and production
  3. Use flamegraphs to find your slowest code