stable_profile 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stable_profile/cli.rb +4 -2
- data/lib/stable_profile.rb +9 -13
- 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: 924cfdff88d8cc5778394fdab96b6bf5e446d92e700e995aaddea7744fbf1eaf
|
4
|
+
data.tar.gz: d80755e9aa8810910baa570e9fca02db34efd52d3cad8bae22fb883f8c5ea2c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1310ffc4a01c70433b737342d862e3de0540168dc43d1e237c4e0549b0376b675efb10435277ae65c15ebda335d25eaf20965b43587453ed742c6728f25959c
|
7
|
+
data.tar.gz: 9ab86cfbd9ec8194c645be23b35d94e3860da7f4a23f6967832cc82f5e84cc7dc4bb31138c4eeb05c403ee97557572b8a2b3fd38a0aaa936e9bac3daba8a82ac
|
data/lib/stable_profile/cli.rb
CHANGED
@@ -4,9 +4,11 @@ require 'stable_profile'
|
|
4
4
|
|
5
5
|
module StableProfile
|
6
6
|
class CLI < Thor
|
7
|
-
desc "profile", "Run RSpec profile
|
7
|
+
desc "profile", "Run RSpec profile multiple times, averaging the results."
|
8
|
+
method_option :iterations, aliases: "-i", type: :numeric, default: 20, desc: "Number of times to run RSpec"
|
9
|
+
method_option :top_slowest_examples, aliases: "-t", type: :numeric, default: 5, desc: "Number of slowest examples to output"
|
8
10
|
def profile
|
9
|
-
StableProfile.run
|
11
|
+
StableProfile.run(iterations: options[:iterations], top_slowest_examples: options[:top_slowest_examples])
|
10
12
|
end
|
11
13
|
default_task :profile
|
12
14
|
end
|
data/lib/stable_profile.rb
CHANGED
@@ -16,13 +16,7 @@ module StableProfile
|
|
16
16
|
module_function
|
17
17
|
|
18
18
|
# How many items to output in each category.
|
19
|
-
TOP_SLOWEST_EXAMPLES = 5
|
20
|
-
|
21
|
-
# The more iterations you run, the more accurate the results will be.
|
22
|
-
ITERATIONS = 20
|
23
|
-
MINIMUM_SAMPLE_SIZE = ITERATIONS * 0.75
|
24
19
|
DECIMAL_PLACES = 4
|
25
|
-
|
26
20
|
OUTPUT_DIR = 'tmp/stable_profile'
|
27
21
|
|
28
22
|
|
@@ -31,14 +25,16 @@ module StableProfile
|
|
31
25
|
end
|
32
26
|
|
33
27
|
|
34
|
-
def run
|
28
|
+
def run(iterations:, top_slowest_examples:)
|
29
|
+
minimum_sample_size = iterations * 0.75
|
30
|
+
|
35
31
|
# Erase and Create the output directory
|
36
32
|
FileUtils.rm_rf(OUTPUT_DIR)
|
37
33
|
FileUtils.mkdir_p(OUTPUT_DIR)
|
38
34
|
|
39
35
|
# Run the specs ITERATIONS times, each time with a different random seed
|
40
|
-
progressbar = ProgressBar.create(title: 'Running profiles', total:
|
41
|
-
|
36
|
+
progressbar = ProgressBar.create(title: 'Running profiles', total: iterations, format: '%t: |%B| %p%% %a')
|
37
|
+
iterations.times do |i|
|
42
38
|
system("rspec --profile --order random --format json > #{OUTPUT_DIR}/multi_profile_#{i+1}.json")
|
43
39
|
progressbar.increment
|
44
40
|
end
|
@@ -77,11 +73,11 @@ module StableProfile
|
|
77
73
|
|
78
74
|
# Mimic RSpec profile output
|
79
75
|
puts
|
80
|
-
puts "Top #{
|
76
|
+
puts "Top #{top_slowest_examples} slowest examples:"
|
81
77
|
count = 0
|
82
78
|
example_times.sort_by { |id, record| record[:average_time] }.reverse.each do |id, record|
|
83
79
|
next if count == TOP_SLOWEST_EXAMPLES
|
84
|
-
next if record[:run_times].size <
|
80
|
+
next if record[:run_times].size < minimum_sample_size
|
85
81
|
count += 1
|
86
82
|
|
87
83
|
example = record.fetch(:example)
|
@@ -91,11 +87,11 @@ module StableProfile
|
|
91
87
|
end
|
92
88
|
|
93
89
|
puts
|
94
|
-
puts "Top #{
|
90
|
+
puts "Top #{top_slowest_examples} slowest example groups:"
|
95
91
|
count = 0
|
96
92
|
group_times.sort_by { |id, record| record[:average_time] }.reverse.each do |id, record|
|
97
93
|
next if count == TOP_SLOWEST_EXAMPLES
|
98
|
-
next if record[:run_times].size <
|
94
|
+
next if record[:run_times].size < minimum_sample_size
|
99
95
|
count += 1
|
100
96
|
|
101
97
|
group = record.fetch(:group)
|