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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fdc1251ab06ef89ebd5900e3159d0783f45c283f47e3e8d536c2f3d264c0f482
4
- data.tar.gz: c46a33e840de54c00ff9be23cef7fa31a95340e2ac8b7866e23e3b0733f54ad4
3
+ metadata.gz: 7a59002ea5da6a514556069ad4094c316d59c1affc362d6f5cd3ea1afc21e697
4
+ data.tar.gz: 6a06ffeb62d321301e169248a94f8b76578dfa3f05683a76347e7152d5099fbc
5
5
  SHA512:
6
- metadata.gz: 3bd390ac4a17735e2d4fab46196c1bce4a3152f1f0b1e958e58d15e03a4b6f83e437fdb8c25fb586f68fcca53b5949201ed10b92ad9076b6417cd948efdc2ab0
7
- data.tar.gz: 2b21c63b395890dac6b1a7f4afef4efda08bb727f1ac339ef2899d718b26a2f06a013c4638ad3edbaa4669e26e2e8298becec6c9b17c6f65cc661a4570a078ab
6
+ metadata.gz: a6a899e53d5404cab959c4b6ac5d54b8564e22ccfbc2a138fb10d0ddaf16eb089240d341bfda3601ae368dd9a4c20740e5e2b20d2c4e3876f8dc3047fc1b4741
7
+ data.tar.gz: e002f7bc8cab5643c276d0af9ad9ecfd66ed45c42a9763ab4299dcd8e359c987a1cd6ee99745460faae05d5226b5126397a1dc793b7fafcaad24bd1d8f1505a2
@@ -4,9 +4,11 @@ require 'stable_profile'
4
4
 
5
5
  module StableProfile
6
6
  class CLI < Thor
7
- desc "profile", "Run RSpec profile with predictable results."
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
@@ -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: ITERATIONS, format: '%t: |%B| %p%% %a')
41
- ITERATIONS.times do |i|
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 #{TOP_SLOWEST_EXAMPLES} slowest examples:"
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 == TOP_SLOWEST_EXAMPLES
84
- next if record[:run_times].size < MINIMUM_SAMPLE_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 #{TOP_SLOWEST_EXAMPLES} slowest example groups:"
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 == TOP_SLOWEST_EXAMPLES
98
- next if record[:run_times].size < MINIMUM_SAMPLE_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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stable_profile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter