stable_profile 0.5.0 → 0.6.1
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/lib/stable_profile/cli.rb +4 -2
- data/lib/stable_profile.rb +11 -15
- 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: 7a59002ea5da6a514556069ad4094c316d59c1affc362d6f5cd3ea1afc21e697
|
4
|
+
data.tar.gz: 6a06ffeb62d321301e169248a94f8b76578dfa3f05683a76347e7152d5099fbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6a899e53d5404cab959c4b6ac5d54b8564e22ccfbc2a138fb10d0ddaf16eb089240d341bfda3601ae368dd9a4c20740e5e2b20d2c4e3876f8dc3047fc1b4741
|
7
|
+
data.tar.gz: e002f7bc8cab5643c276d0af9ad9ecfd66ed45c42a9763ab4299dcd8e359c987a1cd6ee99745460faae05d5226b5126397a1dc793b7fafcaad24bd1d8f1505a2
|
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
|
-
next if count ==
|
84
|
-
next if record[:run_times].size <
|
79
|
+
next if count == top_slowest_examples
|
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
|
-
next if count ==
|
98
|
-
next if record[:run_times].size <
|
93
|
+
next if count == top_slowest_examples
|
94
|
+
next if record[:run_times].size < minimum_sample_size
|
99
95
|
count += 1
|
100
96
|
|
101
97
|
group = record.fetch(:group)
|