pry-auto_benching.rb
Automatic benchmarking inside the Pry REPL.
Configuration can be skipped unless you want to change the defaults.
To change the defaults, open ~/.pryrc
in your editor of choice and change
one or more of the following:
Pry.configure do |config|
config.auto_benching.enabled = false
config.auto_benching.max_history_size = 120
config.auto_benching.clock_type = Process::CLOCK_REALTIME
config.auto_benching.target_display = ':prompt | :none'
config.auto_benching.display_duration_if = ->(pry, duration) { duration >= 0.02 }
config.auto_benching.prompt_color = :red
end
1.
Get started by reading the help menu:
[1] pry(main)> auto-benching -h
Usage: auto-benching [options] [enable|disable]
The auto-benching command can enable, disable, and
provide other features related to pry-auto_benching.rb
-v, --version Display version.
-p, --past Display past benchmark results.
-t, --target-display Choose the target display for results. Valid options are: prompt, none
-h, --help Show this message.
2.
The prompt is updated with benchmark results, this happens to be the default:
[1] pry(main)> sleep 0.2
=> 0
[2] 0.2s (main)> Net::HTTP.get_response URI.parse('https://github.com')
=> #<Net::HTTPOK 200 OK readbody=true>
[3] 1.34s (main)> Net::HTTP.get_response URI.parse('https://www.ruby-lang.org')
=> #<Net::HTTPOK 200 OK readbody=true>
[4] 1.53s (main)>
3.
auto-benching --past
shows past benchmark results:
[1] 1.30s (main)> auto-benching -past
1 0.01 sleep 0.01
2 0.02 sleep 0.02
3 0.03 sleep 0.03
4 1.30 sleep 1.3
5 1.40 Net::HTTP.get_response(URI.parse('https://github.com'))
[2] pry(main)>
4.
Benchmarking can be temporarily disabled then enabled again:
[1] pry(main)> auto-benching disable
pry-auto_benching.rb: stopped benchmarking.
[2] pry(main)> auto-benching enable
pry-auto_benching.rb: started benchmarking.
pry-auto_benching.rb can measure down to 10 milliseconds (0.01 = 10ms).
When I benchmarked sleep 0.01
I saw no overhead in the results:
[1] pry(main)> sleep 0.01
=> 0
[2] 0.01s (main)>
But that's not to say results can't be reported inaccurately since the benchmark
includes a very small number of method calls to Pry internals, and it could
include time spent by other Pry plugins who run before/after eval hooks as well.
I have seen inaccuracies of 10ms (0.01) but not all the time.
gem install pry-auto_benching.rb
This project uses the MIT license, see LICENSE.txt for details.