0.0
No release in over 3 years
Low commit activity in last 3 years
very simple Ruby line profiler
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

gem lineprofiler

Usage

gem install lineprofiler
ruby -r lineprofiler my_slow_program.rb

On exit (wether the program exited or you've interrupted it via ^C) it will print the line profiling report, like this:

...
88.97%  loop do
84.14%    combinations.each do |f, set|
48.97%      t = all.size.times.map do |i|
              [
                all[i].cls,
43.92%          all.values_at(*set-[i]).min_by{ |e| Math.s
              ]
            end
          end
 1.97%    combinations = pcbr.table.sort_by{ |_, _, score|
 1.97%      set.size.times.map do |i|
 1.31%        next if set.size < 3
 0.65%        next if pcbr.set.include? [f, key]
              [f, key]
            end
 2.60%    end.drop_while(&:empty?).first
...

or like this:

...
94.58%  items.group_by{ |x,y,| (px-x).abs + (py-y).abs }...
 0.49%    puts "dist: #{d}"
          add = g.flat_map(&:last).sort
          until add.empty?
            acc.replace acc | add
93.63%      a, b = all.partition do |id, rec|
55.88%        unless (rec & add).empty?
24.51%          if (rec - acc).empty?
13.24%            (puts "#{id} = #{rec.join " + "}"; true)
                end
...

By default it reports only about the main file -- $0, but you can pass a path to another source file (for example a library dependency that your program calls often) as a LINEPROFILER env var so it will print it too afterwards:

$ LINEPROFILER=lib/rasel.rb ruby -rlineprofiler constants_print.rb
...
constants_print.rb
  ...  
lib/rasel.rb
  ...

You are supposed to pass this env var if you run the code via -e. Also note that in the next example we require the library we want to profiler before the profiler so we don't profile the initialization but only the invocation step:

$ LINEPROFILER=common.rb bundle exec ruby -r./common -rlineprofiler -e 'puts Common.my_method'