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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fdc1251ab06ef89ebd5900e3159d0783f45c283f47e3e8d536c2f3d264c0f482
4
- data.tar.gz: c46a33e840de54c00ff9be23cef7fa31a95340e2ac8b7866e23e3b0733f54ad4
3
+ metadata.gz: 924cfdff88d8cc5778394fdab96b6bf5e446d92e700e995aaddea7744fbf1eaf
4
+ data.tar.gz: d80755e9aa8810910baa570e9fca02db34efd52d3cad8bae22fb883f8c5ea2c5
5
5
  SHA512:
6
- metadata.gz: 3bd390ac4a17735e2d4fab46196c1bce4a3152f1f0b1e958e58d15e03a4b6f83e437fdb8c25fb586f68fcca53b5949201ed10b92ad9076b6417cd948efdc2ab0
7
- data.tar.gz: 2b21c63b395890dac6b1a7f4afef4efda08bb727f1ac339ef2899d718b26a2f06a013c4638ad3edbaa4669e26e2e8298becec6c9b17c6f65cc661a4570a078ab
6
+ metadata.gz: f1310ffc4a01c70433b737342d862e3de0540168dc43d1e237c4e0549b0376b675efb10435277ae65c15ebda335d25eaf20965b43587453ed742c6728f25959c
7
+ data.tar.gz: 9ab86cfbd9ec8194c645be23b35d94e3860da7f4a23f6967832cc82f5e84cc7dc4bb31138c4eeb05c403ee97557572b8a2b3fd38a0aaa936e9bac3daba8a82ac
@@ -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
79
  next if count == TOP_SLOWEST_EXAMPLES
84
- next if record[:run_times].size < MINIMUM_SAMPLE_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 #{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
93
  next if count == TOP_SLOWEST_EXAMPLES
98
- next if record[:run_times].size < MINIMUM_SAMPLE_SIZE
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter