1 comment

[ 1.9 ms ] story [ 16.4 ms ] thread
Neat! Note that using Ruby's profiler is a heck of a lot easier. For example, here's how you can profile a call to a model method in Rails: http://stufftohelpyouout.blogspot.com/2013/05/profiling-in-r...

    rails c 2>&1 | tee profile.txt
    require 'profile'
    SomeClass.some_method
    exit (or ctrl-d)
    grep -E "SomeClass\#|cumulative   self|seconds    call" profile.txt
Example of results:

      %   cumulative   self              self     total
     time   seconds   seconds    calls  ms/call  ms/call  name
    1.05     0.79      0.01        5     2.00     2.00  SomeClass#_validate_callbacks
    0.00     0.95      0.00       13     0.00     0.00  SomeClass#_create_callbacks
    0.00     0.95      0.00       13     0.00     0.00  SomeClass#_update_callbacks
    0.00     0.95      0.00       15     0.00     0.00  SomeClass#reflections
    0.00     0.95      0.00       12     0.00     0.00  SomeClass#_save_callbacks
    ...
Other things to look at:

* Benchmark: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/benchmark/rdoc/B...

* Rails perf testing: http://guides.rubyonrails.org/performance_testing.html

* Ruby-prof: https://github.com/rdp/ruby-prof

* Tracer: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/tracer/rdoc/inde...

* TracePoint: https://github.com/rubyunworks/tracepoint

* Autolog: https://github.com/garysweaver/autolog

* set_trace_func: http://apidock.com/ruby/Kernel/set_trace_func

See also: http://stackoverflow.com/a/16700778/178651