pry-auto_benching.rb 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +6 -5
- data/lib/pry-auto_benching.rb +32 -68
- data/lib/pry-auto_benching/moment_list.rb +41 -0
- data/lib/pry-auto_benching/pry_command.rb +11 -12
- data/lib/pry-auto_benching/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 045cf80b47b7e90cd9b0ce925106b37e9280ca87ef74f603a264cfa442718b19
|
4
|
+
data.tar.gz: ebaf1241f1974405a91b6e2255561c43ff0b9401083eb6eccbff6c92769cf486
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 126752554d260b8e977e86478aad4d8b251598762e9a4ab74fbbe7ee6d0f5f9bb22e76817c71b91e2605aec5067c5f26de2ed5c52fd880b87a2838210f6e683c
|
7
|
+
data.tar.gz: e5c63c874fb755a6f1f63f2e041ac6c80bb1cb94dc991133e2e61bb0aae584aaa24530f3819a980420c995ff79d6518961ea7864de66dc854251874459a992c2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## v3.1.0
|
4
|
+
|
5
|
+
* Align the index, duration, and line of input in the output of
|
6
|
+
`auto-benching --past`.
|
7
|
+
|
8
|
+
* Improve `auto-benching --past` by modifying its output.
|
9
|
+
|
10
|
+
* Fix a typo shown when choosing an invalid target display.
|
11
|
+
|
3
12
|
## v3.0.0
|
4
13
|
|
5
14
|
* Remove `:output` as a target display, and the related code that supported
|
data/README.md
CHANGED
@@ -97,11 +97,12 @@ __3.__
|
|
97
97
|
|
98
98
|
`auto-benching --past` shows past benchmark results:
|
99
99
|
|
100
|
-
[1]
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
100
|
+
[1] 1.30s (main)> auto-benching -past
|
101
|
+
1 0.01 sleep 0.01
|
102
|
+
2 0.02 sleep 0.02
|
103
|
+
3 0.03 sleep 0.03
|
104
|
+
4 1.30 sleep 1.3
|
105
|
+
5 1.40 Net::HTTP.get_response(URI.parse('https://github.com'))
|
105
106
|
[2] pry(main)>
|
106
107
|
|
107
108
|
__4.__
|
data/lib/pry-auto_benching.rb
CHANGED
@@ -1,50 +1,9 @@
|
|
1
1
|
module Pry::AutoBenching
|
2
2
|
require 'pry'
|
3
3
|
require 'pry-auto_benching/version'
|
4
|
+
require 'pry-auto_benching/moment_list'
|
4
5
|
require 'pry-auto_benching/pry_command'
|
5
6
|
|
6
|
-
#
|
7
|
-
# MomentList is an Array-like object who cycles its contents
|
8
|
-
# when a max size is reached.
|
9
|
-
#
|
10
|
-
# @api private
|
11
|
-
#
|
12
|
-
MomentList = Class.new do
|
13
|
-
include Enumerable
|
14
|
-
|
15
|
-
def initialize(pry)
|
16
|
-
@pry = pry
|
17
|
-
@ary = []
|
18
|
-
end
|
19
|
-
|
20
|
-
def each
|
21
|
-
@ary.each do |moment|
|
22
|
-
yield moment
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def [](index)
|
27
|
-
@ary[index]
|
28
|
-
end
|
29
|
-
|
30
|
-
def pop
|
31
|
-
@ary.pop
|
32
|
-
end
|
33
|
-
|
34
|
-
def empty?
|
35
|
-
@ary.empty?
|
36
|
-
end
|
37
|
-
|
38
|
-
def <<(other)
|
39
|
-
@ary.shift if @ary.size + 1 > max_size
|
40
|
-
@ary << other
|
41
|
-
end
|
42
|
-
|
43
|
-
def max_size
|
44
|
-
@pry.config.auto_benching.max_history_size
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
7
|
#
|
49
8
|
# @api private
|
50
9
|
#
|
@@ -53,21 +12,6 @@ module Pry::AutoBenching
|
|
53
12
|
attr_accessor :duration
|
54
13
|
end
|
55
14
|
|
56
|
-
write_duration = -> (pry, duration) {
|
57
|
-
auto_benching = pry.config.auto_benching
|
58
|
-
target_display = auto_benching.target_display.to_s
|
59
|
-
pry.config.forget(:prompt_name)
|
60
|
-
if target_display == 'prompt'
|
61
|
-
pry.config.prompt_name = "#{Pry::Helpers::Text.send(auto_benching.prompt_color, duration.to_s + 's')} "
|
62
|
-
elsif target_display == 'none'
|
63
|
-
# no op
|
64
|
-
else
|
65
|
-
pry.output.warn "_pry_.config.auto_benching.target_display has an invalid value " \
|
66
|
-
"(#{auto_benching.target_display.inspect}). \n" \
|
67
|
-
"It should be equal to ':output', ':prompt' or ':none'"
|
68
|
-
end
|
69
|
-
}
|
70
|
-
|
71
15
|
@moments = Hash.new do |h, pry|
|
72
16
|
h[pry.hash] = MomentList.new(pry)
|
73
17
|
end
|
@@ -81,10 +25,10 @@ module Pry::AutoBenching
|
|
81
25
|
@after_eval = ->(_, pry) do
|
82
26
|
auto_benching = pry.config.auto_benching
|
83
27
|
moment = @moments[pry.hash][-1]
|
84
|
-
moment.duration =
|
28
|
+
moment.duration = Process.clock_gettime(auto_benching.clock_type) - moment.start_timestamp.to_f
|
85
29
|
if auto_benching.display_duration_if.call(pry, moment.duration)
|
86
30
|
moment.input = pry.input_ring.to_a[-1]
|
87
|
-
write_duration
|
31
|
+
write_duration(pry, moment.duration)
|
88
32
|
else
|
89
33
|
@moments[pry.hash].pop
|
90
34
|
pry.config.forget(:prompt_name)
|
@@ -140,6 +84,34 @@ module Pry::AutoBenching
|
|
140
84
|
@moments
|
141
85
|
end
|
142
86
|
|
87
|
+
#
|
88
|
+
# @api private
|
89
|
+
#
|
90
|
+
def self.write_duration(pry, duration)
|
91
|
+
auto_benching = pry.config.auto_benching
|
92
|
+
target = auto_benching.target_display.to_s
|
93
|
+
pry.config.forget(:prompt_name)
|
94
|
+
if target == 'prompt'
|
95
|
+
pry.config.prompt_name = Pry::Helpers::Text.send auto_benching.prompt_color,
|
96
|
+
format_duration(duration)
|
97
|
+
elsif target == 'none'
|
98
|
+
# no op
|
99
|
+
else
|
100
|
+
pry.output.warn "_pry_.config.auto_benching.target_display has an invalid value: \n" \
|
101
|
+
"#{auto_benching.target_display.inspect}\n" \
|
102
|
+
"Valid values are: " \
|
103
|
+
"#{Pry::AutoBenching::PryCommand::VALID_TARGET_DISPLAYS.join(', ')}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
# @api private
|
109
|
+
#
|
110
|
+
def self.format_duration(float)
|
111
|
+
duration = Kernel.sprintf("%.2f", float).ljust(4)
|
112
|
+
"#{duration}s "
|
113
|
+
end
|
114
|
+
|
143
115
|
Pry.configure do |config|
|
144
116
|
config.hooks.add_hook :before_session, @before_session.hash, @before_session
|
145
117
|
config.auto_benching = Pry::Config.from_hash({
|
@@ -148,15 +120,7 @@ module Pry::AutoBenching
|
|
148
120
|
target_display: :prompt,
|
149
121
|
prompt_color: :green,
|
150
122
|
clock_type: Process::CLOCK_MONOTONIC,
|
151
|
-
display_duration_if: ->(pry, duration) { duration >= 0.01 }
|
152
|
-
output_string: ->(pry, duration) {
|
153
|
-
format("%{TextDesc} %{Duration}s", {
|
154
|
-
:TextDesc => pry.color ?
|
155
|
-
Pry::Helpers::Text.green("pry-auto_benching.rb:") :
|
156
|
-
"pry-auto_benching.rb:",
|
157
|
-
:Duration => sprintf("%.2f", duration)
|
158
|
-
})
|
159
|
-
}
|
123
|
+
display_duration_if: ->(pry, duration) { duration >= 0.01 }
|
160
124
|
})
|
161
125
|
end
|
162
126
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# MomentList is an Array-like object who cycles its contents
|
3
|
+
# when a max size is reached.
|
4
|
+
#
|
5
|
+
# @api private
|
6
|
+
#
|
7
|
+
class Pry::AutoBenching::MomentList
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
def initialize(pry)
|
11
|
+
@pry = pry
|
12
|
+
@ary = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def each
|
16
|
+
@ary.each do |moment|
|
17
|
+
yield moment
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def [](index)
|
22
|
+
@ary[index]
|
23
|
+
end
|
24
|
+
|
25
|
+
def pop
|
26
|
+
@ary.pop
|
27
|
+
end
|
28
|
+
|
29
|
+
def empty?
|
30
|
+
@ary.empty?
|
31
|
+
end
|
32
|
+
|
33
|
+
def <<(other)
|
34
|
+
@ary.shift if @ary.size + 1 > max_size
|
35
|
+
@ary << other
|
36
|
+
end
|
37
|
+
|
38
|
+
def max_size
|
39
|
+
@pry.config.auto_benching.max_history_size
|
40
|
+
end
|
41
|
+
end
|
@@ -30,12 +30,9 @@ class Pry::AutoBenching::PryCommand < Pry::ClassCommand
|
|
30
30
|
|
31
31
|
def process(command)
|
32
32
|
case
|
33
|
-
when opts.version?
|
34
|
-
|
35
|
-
when opts.present?('
|
36
|
-
change_target_display(opts[:'target-display'])
|
37
|
-
when opts.present?('past')
|
38
|
-
process_past
|
33
|
+
when opts.version? then page(VERSION_STRING)
|
34
|
+
when opts.present?('target-display') then change_target_display(opts[:'target-display'])
|
35
|
+
when opts.present?('past') then read_past_benchmarks
|
39
36
|
else
|
40
37
|
if command == 'enable'
|
41
38
|
Pry::AutoBenching.enable(_pry_)
|
@@ -52,16 +49,18 @@ class Pry::AutoBenching::PryCommand < Pry::ClassCommand
|
|
52
49
|
|
53
50
|
private
|
54
51
|
|
55
|
-
def
|
52
|
+
def read_past_benchmarks
|
56
53
|
moments = Pry::AutoBenching.moments[_pry_.hash]
|
57
54
|
if moments.empty?
|
58
55
|
page "No benchmark results are stored for this session."
|
59
56
|
else
|
60
|
-
page moments.map.with_index {
|
61
|
-
format "%{
|
62
|
-
|
57
|
+
page moments.map.with_index {|moment,i|
|
58
|
+
format "%{i} %{duration}%{code}",
|
59
|
+
i: bold(i+1),
|
63
60
|
code: moment.input.chomp,
|
64
|
-
duration:
|
61
|
+
duration: green(
|
62
|
+
Pry::AutoBenching.format_duration(moment.duration).sub('s', '')
|
63
|
+
)
|
65
64
|
}.join("\n")
|
66
65
|
end
|
67
66
|
end
|
@@ -71,7 +70,7 @@ class Pry::AutoBenching::PryCommand < Pry::ClassCommand
|
|
71
70
|
_pry_.config.auto_benching.target_display = target_display
|
72
71
|
page "Display changed to '#{target_display}'"
|
73
72
|
else
|
74
|
-
raise Pry::CommandError, "'#{target_display}' is
|
73
|
+
raise Pry::CommandError, "'#{target_display}' is invalid, " \
|
75
74
|
"valid options are: #{VALID_TARGET_DISPLAYS.join(', ')}"
|
76
75
|
end
|
77
76
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-auto_benching.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Gleeson
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- LICENSE.txt
|
35
35
|
- README.md
|
36
36
|
- lib/pry-auto_benching.rb
|
37
|
+
- lib/pry-auto_benching/moment_list.rb
|
37
38
|
- lib/pry-auto_benching/pry_command.rb
|
38
39
|
- lib/pry-auto_benching/version.rb
|
39
40
|
- pry-auto_benching.gemspec
|