pry-auto_benching.rb 1.4.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -10
- data/lib/pry-auto_benching/version.rb +1 -1
- data/lib/pry-auto_benching.rb +30 -31
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be1a301f4640fa309396d5060f2604de2c5cae2874af83386fdb78501d46e516
|
4
|
+
data.tar.gz: 339a0fe540e98b1383b01236c22a3393307549463982dcee42db424d0dcb1762
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fdc62c926d94143785aef3829dda820e34129edb21318623050437befcef2fefc934aaf196c52d725598fc33aba9b9a3c9472dd04f6e141f71f5ce5a596ee50
|
7
|
+
data.tar.gz: c9bc0911ad06d752849ba1c038b1f310702eab85e3c9dcc9d758eebe674d2778de5e3c72ef8c4a37569e638f1d9d6dd12226fa93c5d6ad1951a9e275f5109ec3
|
data/README.md
CHANGED
@@ -20,23 +20,22 @@ Pry.configure do |config|
|
|
20
20
|
config.auto_benching.clock_type = Process::CLOCK_REALTIME
|
21
21
|
|
22
22
|
# Configure where benchmark results should be displayed, either
|
23
|
-
# in the prompt or written to
|
23
|
+
# in the prompt or written to `_pry_.output`. Default is :prompt.
|
24
24
|
config.auto_benching.target_display = ':prompt | :output'
|
25
25
|
|
26
|
-
# Benchmark results are printed depending on the return value
|
27
|
-
# of this lambda, by default results are
|
28
|
-
config.auto_benching.
|
29
|
-
duration > 0.5
|
30
|
-
}
|
26
|
+
# Benchmark results are printed or not depending on the return value
|
27
|
+
# of this lambda, by default results are printed when duration > 0.0.
|
28
|
+
config.auto_benching.display_duration_if = ->(pry, duration) { duration >= 0.2 }
|
31
29
|
|
32
30
|
# The color to use for benchmark results when `target_display` is :prompt.
|
33
31
|
# The default is :green.
|
34
32
|
config.auto_benching.prompt_color = :red
|
35
33
|
|
36
|
-
# A lambda
|
37
|
-
# is
|
38
|
-
|
39
|
-
|
34
|
+
# A lambda that returns a string for display on `_pry_.output` (usually $stdout).
|
35
|
+
# This lambda is used when `target_display` is equal to `:output`.
|
36
|
+
# Default is: "pry-auto_benching.rb: %.2fs".
|
37
|
+
config.auto_benching.output_string = ->(pry, duration) {
|
38
|
+
sprintf("elapsed time: %.2fs", duration)
|
40
39
|
}
|
41
40
|
end
|
42
41
|
```
|
data/lib/pry-auto_benching.rb
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
module Pry::AutoBenching
|
2
|
+
write_duration = -> (pry, duration) {
|
3
|
+
auto_benching = pry.config.auto_benching
|
4
|
+
if auto_benching.target_display == :prompt
|
5
|
+
pry.config.prompt_name = Pry.lazy { "#{Pry::Helpers::Text.send(auto_benching.prompt_color, duration.to_s + 's')} " }
|
6
|
+
elsif auto_benching.target_display == :output
|
7
|
+
pry.pager.page auto_benching.output_string.call(pry, duration)
|
8
|
+
else
|
9
|
+
raise Pry::CommandError,
|
10
|
+
"_pry_.config.auto_benching.target_display has an invalid value (#{auto_benching.target_display})"
|
11
|
+
end
|
12
|
+
}
|
13
|
+
|
2
14
|
MEMORY = Hash.new{|h,k| h[k] = [] }
|
3
15
|
|
4
16
|
BEFORE_EVAL = ->(_, pry) do
|
@@ -6,36 +18,23 @@ module Pry::AutoBenching
|
|
6
18
|
MEMORY[pry.hash].push Process.clock_gettime(clock_type)
|
7
19
|
end
|
8
20
|
|
9
|
-
write_result = ->(pry, duration) {
|
10
|
-
target_display = pry.config.auto_benching.target_display
|
11
|
-
if target_display == :prompt
|
12
|
-
prompt_color = pry.config.auto_benching.prompt_color
|
13
|
-
pry.config.prompt_name = Pry.lazy {
|
14
|
-
"#{Pry::Helpers::Text.send(prompt_color, duration.to_s + 's')} "
|
15
|
-
}
|
16
|
-
elsif target_display == :output
|
17
|
-
pry.config.auto_benching.speaker.call(pry, duration)
|
18
|
-
else
|
19
|
-
raise Pry::CommandError, "_pry_.config.auto_benching.target_display has an invalid value (#{target_display})"
|
20
|
-
end
|
21
|
-
}
|
22
|
-
|
23
21
|
AFTER_EVAL = ->(input, pry) do
|
24
|
-
|
25
|
-
duration = (sprintf "%.2f", Process.clock_gettime(clock_type) - MEMORY[pry.hash].pop).to_f
|
22
|
+
auto_benching = pry.config.auto_benching
|
23
|
+
duration = (sprintf "%.2f", Process.clock_gettime(auto_benching.clock_type) - MEMORY[pry.hash].pop).to_f
|
26
24
|
if input.nil? # Pry command
|
27
|
-
if
|
28
|
-
|
29
|
-
|
25
|
+
if auto_benching.benchmark_commands and
|
26
|
+
auto_benching.display_duration_if.call(pry, duration)
|
27
|
+
write_duration.call(pry, duration)
|
28
|
+
elsif auto_benching.target_display == :prompt
|
29
|
+
pry.config.prompt_name = Pry::Prompt::DEFAULT_NAME
|
30
30
|
end
|
31
|
-
else
|
32
|
-
if
|
33
|
-
|
34
|
-
|
35
|
-
pry.config.prompt_name =
|
31
|
+
else # Ruby code
|
32
|
+
if auto_benching.display_duration_if.call(pry, duration)
|
33
|
+
write_duration.call(pry, duration)
|
34
|
+
elsif auto_benching.target_display == :prompt
|
35
|
+
pry.config.prompt_name = Pry::Prompt::DEFAULT_NAME
|
36
36
|
end
|
37
37
|
end
|
38
|
-
pry.config.prompt_name = 'pry' if pry.config.auto_benching.target_display != :prompt
|
39
38
|
end
|
40
39
|
|
41
40
|
BEFORE_SESSION = ->(_,_, pry) do
|
@@ -95,13 +94,13 @@ Pry.configure do |config|
|
|
95
94
|
target_display: :prompt,
|
96
95
|
prompt_color: :green,
|
97
96
|
clock_type: Process::CLOCK_MONOTONIC,
|
97
|
+
display_duration_if: ->(pry, duration) { duration > 0.0 },
|
98
98
|
benchmark_commands: true,
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
"pry-auto_benching.rb:",
|
99
|
+
output_string: ->(pry, duration) {
|
100
|
+
format("%{TextDesc} %{Duration}s", {
|
101
|
+
:TextDesc => pry.color ?
|
102
|
+
Pry::Helpers::Text.green("pry-auto_benching.rb:") :
|
103
|
+
"pry-auto_benching.rb:",
|
105
104
|
:Duration => sprintf("%.2f", duration)
|
106
105
|
})
|
107
106
|
}
|