pry-auto_benching.rb 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +32 -24
- data/lib/pry-auto_benching/version.rb +1 -1
- data/lib/pry-auto_benching.rb +54 -31
- data/pry-auto_benching.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0612c1d96859e2c9d813bba4572dd26019406bea956909cf56fa3a9c7952b00
|
4
|
+
data.tar.gz: 622b628f5055fc504b97fa12a638a5c8344834d91c25bcbc5e417a85c659f7d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42a4169779af83587da49fef60cc01e4b3f49425b61e783c1c12b4ad01db4875808a17f2cc93a2280f379648176a7b02e82ae8bef3c38e590a351d17e91ac1de
|
7
|
+
data.tar.gz: 57755f3a2d39f39ca0b585a8ec0283fc63f8d21bedf5904e17853873d7f4e4229229e0642886503e821a805f2ad6333ea621d7398b65ef2ac656899787daf038
|
data/README.md
CHANGED
@@ -19,14 +19,22 @@ Pry.configure do |config|
|
|
19
19
|
# See https://www.rubydoc.info/stdlib/core/Process:clock_gettime
|
20
20
|
config.auto_benching.clock_type = Process::CLOCK_REALTIME
|
21
21
|
|
22
|
+
# Configure where benchmark results should be displayed, either
|
23
|
+
# in the prompt or written to stdout. Default is :prompt.
|
24
|
+
config.auto_benching.target_display = ':prompt | :stdout'
|
25
|
+
|
22
26
|
# Benchmark results are printed depending on the return value
|
23
|
-
# of this lambda, by default results are printed if duration
|
27
|
+
# of this lambda, by default results are printed if duration >= 0.1s
|
24
28
|
config.auto_benching.speak_if = ->(pry, duration) {
|
25
29
|
duration > 0.5
|
26
30
|
}
|
27
31
|
|
28
|
-
#
|
29
|
-
#
|
32
|
+
# The color to use for benchmark results when `target_display` is :prompt.
|
33
|
+
# The default is :green.
|
34
|
+
config.auto_benching.prompt_color = :red
|
35
|
+
|
36
|
+
# A lambda for presenting the benchmark results when `target_display`
|
37
|
+
# is :stdout. Default is: "Benchmark: %.2fs".
|
30
38
|
config.auto_benching.speaker = ->(pry, duration) {
|
31
39
|
pry.pager.page sprintf("Elapsed time: %.2fs", duration)
|
32
40
|
}
|
@@ -37,10 +45,10 @@ end
|
|
37
45
|
|
38
46
|
__1.__
|
39
47
|
|
40
|
-
Show help by running `
|
48
|
+
Show help by running `auto-benching -h`:
|
41
49
|
|
42
|
-
[1] pry(main)>
|
43
|
-
Usage:
|
50
|
+
[1] pry(main)> auto-benching -h
|
51
|
+
Usage: auto-benching [enable|disable]
|
44
52
|
|
45
53
|
Enable or disable benchmarking of input.
|
46
54
|
|
@@ -48,34 +56,34 @@ Show help by running `pry-auto_benching -h`:
|
|
48
56
|
|
49
57
|
__2.__
|
50
58
|
|
51
|
-
Disable auto benchmarking by running `
|
59
|
+
Disable auto benchmarking by running `auto-benching disable`:
|
52
60
|
|
53
|
-
[1] pry(main)>
|
54
|
-
pry-auto_benching.rb: 2.00s
|
55
|
-
=> 2
|
56
|
-
[2] pry(main)> pry-auto_benching disable
|
61
|
+
[1] pry(main)> auto-benching disable
|
57
62
|
pry-auto_benching.rb: stopped benchmarking.
|
58
|
-
[
|
63
|
+
[2] pry(main)> sleep 2
|
59
64
|
=> 2
|
60
65
|
|
61
66
|
__3.__
|
62
67
|
|
63
|
-
|
64
|
-
|
68
|
+
A screenshot, using `:prompt` as the target_display.
|
69
|
+
The prompt name (by default 'pry') is replaced with the benchmark results
|
70
|
+
for the previous expression. This is the default since it is subtle, yet
|
71
|
+
easy to spot in a sea of output.
|
72
|
+
|
73
|
+

|
65
74
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
75
|
+
__4.__
|
76
|
+
|
77
|
+
A screenshot, using `:stdout` as the target_display.
|
78
|
+
To switch to using this display, run `_pry_.config.auto_benching.target_display = :stdout`
|
79
|
+
inside the repl or set `Pry.config.auto_benching.target_display` from your .pryrc for a
|
80
|
+
permanent change.
|
81
|
+
|
82
|
+

|
73
83
|
|
74
84
|
## Install
|
75
85
|
|
76
|
-
|
77
|
-
gem "pry-auto_benching.rb", github: "r-obert/pry-auto_benching.rb"
|
78
|
-
```
|
86
|
+
gem install pry-auto_benching.rb
|
79
87
|
|
80
88
|
## License
|
81
89
|
|
data/lib/pry-auto_benching.rb
CHANGED
@@ -6,17 +6,36 @@ module Pry::AutoBenching
|
|
6
6
|
MEMORY[pry.hash].push Process.clock_gettime(clock_type)
|
7
7
|
end
|
8
8
|
|
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 == :stdout
|
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
|
+
|
9
23
|
AFTER_EVAL = ->(input, pry) do
|
10
24
|
clock_type = pry.config.auto_benching.clock_type
|
11
25
|
duration = (sprintf "%.2f", Process.clock_gettime(clock_type) - MEMORY[pry.hash][-1]).to_f
|
12
26
|
if input.nil? # Pry command
|
13
|
-
pry.config.auto_benching.benchmark_commands and
|
14
|
-
|
15
|
-
|
27
|
+
if pry.config.auto_benching.benchmark_commands and
|
28
|
+
pry.config.auto_benching.speak_if.call(pry, duration)
|
29
|
+
write_result.(pry, duration)
|
30
|
+
end
|
16
31
|
else
|
17
|
-
pry.config.auto_benching.speak_if.call(pry, duration)
|
18
|
-
|
32
|
+
if pry.config.auto_benching.speak_if.call(pry, duration)
|
33
|
+
write_result.(pry, duration)
|
34
|
+
else
|
35
|
+
pry.config.prompt_name = 'pry'
|
36
|
+
end
|
19
37
|
end
|
38
|
+
pry.config.prompt_name = 'pry' if pry.config.auto_benching.target_display != :prompt
|
20
39
|
MEMORY[pry.hash].clear
|
21
40
|
end
|
22
41
|
|
@@ -42,45 +61,49 @@ module Pry::AutoBenching
|
|
42
61
|
pry.config.hooks.delete_hook :after_session , AFTER_SESSION.hash
|
43
62
|
MEMORY[pry.hash].clear
|
44
63
|
end
|
64
|
+
end
|
45
65
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
66
|
+
require 'pry' if not defined?(Pry::ClassCommand)
|
67
|
+
Pry::Commands.add_command Class.new(Pry::ClassCommand) {
|
68
|
+
match 'auto-benching'
|
69
|
+
command_options argument_required: true
|
70
|
+
group 'pry-auto_benching.rb'
|
71
|
+
description 'Enable or disable benchmarking.'
|
72
|
+
banner <<-CMDBANNER
|
73
|
+
Usage: pry-auto_benching [enable|disable]
|
54
74
|
|
55
|
-
|
56
|
-
|
75
|
+
Enable or disable benchmarking code (or Pry commands).
|
76
|
+
CMDBANNER
|
57
77
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
78
|
+
def process(command)
|
79
|
+
if command == 'enable'
|
80
|
+
Pry::AutoBenching.enable(_pry_)
|
81
|
+
_pry_.pager.page('pry-auto_benching.rb: benchmarking.')
|
82
|
+
elsif command == 'disable'
|
83
|
+
Pry::AutoBenching.disable(_pry_)
|
84
|
+
_pry_.pager.page('pry-auto_benching.rb: stopped benchmarking.')
|
85
|
+
else
|
86
|
+
raise Pry::CommandError, "'#{command}' is not implemented by this command, try -h for help."
|
68
87
|
end
|
69
88
|
end
|
89
|
+
}
|
70
90
|
|
71
|
-
|
72
|
-
|
73
|
-
|
91
|
+
Pry.configure do |config|
|
92
|
+
config.hooks.add_hook :before_session, Pry::AutoBenching::BEFORE_SESSION.hash,
|
93
|
+
Pry::AutoBenching::BEFORE_SESSION
|
94
|
+
config.auto_benching = Pry::Config.from_hash({
|
74
95
|
enabled: true,
|
96
|
+
target_display: :prompt,
|
97
|
+
prompt_color: :green,
|
75
98
|
clock_type: Process::CLOCK_MONOTONIC,
|
76
99
|
benchmark_commands: false,
|
77
|
-
speak_if: ->(pry, duration) { duration
|
100
|
+
speak_if: ->(pry, duration) { duration >= 0.1 },
|
78
101
|
speaker: ->(pry, duration) {
|
79
|
-
pry.pager.page format("%{AutoBenchingSays} %{
|
102
|
+
pry.pager.page format("%{AutoBenchingSays} %{Duration}s", {
|
80
103
|
:AutoBenchingSays => pry.color ?
|
81
104
|
Pry::Helpers::Text.green("pry-auto_benching.rb:") :
|
82
105
|
"pry-auto_benching.rb:",
|
83
|
-
:
|
106
|
+
:Duration => sprintf("%.2f", duration)
|
84
107
|
})
|
85
108
|
}
|
86
109
|
}, nil)
|
data/pry-auto_benching.gemspec
CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
|
|
4
4
|
spec.version = Pry::AutoBenching::VERSION
|
5
5
|
spec.authors = ["Robert Gleeson"]
|
6
6
|
spec.email = "trebor.g@protonmail.com"
|
7
|
-
spec.summary = "Pry plugin
|
7
|
+
spec.summary = "Pry plugin that automatically benchmarks input given to Pry."
|
8
8
|
spec.description = spec.summary
|
9
9
|
spec.homepage = "https://github.com/r-obert/pry-auto_benching.rb"
|
10
10
|
spec.licenses = ["MIT"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-auto_benching.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Gleeson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.11'
|
27
|
-
description: Pry plugin
|
27
|
+
description: Pry plugin that automatically benchmarks input given to Pry.
|
28
28
|
email: trebor.g@protonmail.com
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
@@ -58,5 +58,5 @@ rubyforge_project:
|
|
58
58
|
rubygems_version: 2.7.7
|
59
59
|
signing_key:
|
60
60
|
specification_version: 4
|
61
|
-
summary: Pry plugin
|
61
|
+
summary: Pry plugin that automatically benchmarks input given to Pry.
|
62
62
|
test_files: []
|