stable_profile 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/stable_profile.rb +17 -19
  3. metadata +21 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 302e1a928fc81f6d35e7f00419d6def5389f84ffbee1a49c37d46268c0769fd0
4
- data.tar.gz: 172cc9fffbf9c3601328f23be2ed0c49551d9849131fdb8898f6117b04d99e1d
3
+ metadata.gz: fdc1251ab06ef89ebd5900e3159d0783f45c283f47e3e8d536c2f3d264c0f482
4
+ data.tar.gz: c46a33e840de54c00ff9be23cef7fa31a95340e2ac8b7866e23e3b0733f54ad4
5
5
  SHA512:
6
- metadata.gz: dbf59497da62a1ded24a969a699baeb26819b974069db9bd0c126c8c4ea9acecf46b44822b851a39ccf511fc9ede30aaccaebb0dfca296bcd13525db8737db61
7
- data.tar.gz: f0f6877b89257b90aaca0868af3c5eb4209a2dbc007287de54a7e6aa19b3edbf6a73616bd878df52534eab03538d0ca56e81d3e0a67d6b63117087c5e7873c25
6
+ metadata.gz: 3bd390ac4a17735e2d4fab46196c1bce4a3152f1f0b1e958e58d15e03a4b6f83e437fdb8c25fb586f68fcca53b5949201ed10b92ad9076b6417cd948efdc2ab0
7
+ data.tar.gz: 2b21c63b395890dac6b1a7f4afef4efda08bb727f1ac339ef2899d718b26a2f06a013c4638ad3edbaa4669e26e2e8298becec6c9b17c6f65cc661a4570a078ab
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'colorize'
3
4
  require 'fileutils'
4
5
  require 'json'
5
6
  require 'ruby-progressbar'
@@ -12,27 +13,22 @@ module StableProfile
12
13
  # --iterations 10
13
14
  # --top-slowest-examples 10
14
15
 
15
- class String
16
- def bold
17
- "\e[1m#{self}\e[22m"
18
- end
19
- end
20
-
21
16
  module_function
22
17
 
23
18
  # How many items to output in each category.
24
19
  TOP_SLOWEST_EXAMPLES = 5
25
20
 
26
21
  # The more iterations you run, the more accurate the results will be.
27
- # 20 seems like plenty, but it could take a while depending on the
28
- # size of your test suite.
29
- ITERATIONS = 4
22
+ ITERATIONS = 20
23
+ MINIMUM_SAMPLE_SIZE = ITERATIONS * 0.75
24
+ DECIMAL_PLACES = 4
30
25
 
31
- # It's a slow one if it showed up in at least half the profile runs.
32
- MINIMUM_SAMPLE_SIZE = ITERATIONS / 2
33
- DECIMAL_PLACES = 4
26
+ OUTPUT_DIR = 'tmp/stable_profile'
34
27
 
35
- OUTPUT_DIR = 'tmp/multi_profile'
28
+
29
+ def bold(string)
30
+ "\e[1m#{string}\e[22m"
31
+ end
36
32
 
37
33
 
38
34
  def run
@@ -43,12 +39,14 @@ module StableProfile
43
39
  # Run the specs ITERATIONS times, each time with a different random seed
44
40
  progressbar = ProgressBar.create(title: 'Running profiles', total: ITERATIONS, format: '%t: |%B| %p%% %a')
45
41
  ITERATIONS.times do |i|
46
- system("rspec --profile 50 --order random --format json > #{OUTPUT_DIR}/multi_profile_#{i+1}.json")
42
+ system("rspec --profile --order random --format json > #{OUTPUT_DIR}/multi_profile_#{i+1}.json")
47
43
  progressbar.increment
48
44
  end
49
45
 
50
46
  # Read the results from the JSON files into an array.
51
- outputs = Dir.glob("#{OUTPUT_DIR}/*.json").map { |file| JSON.parse(File.read(file)) }
47
+ outputs = Dir.glob("#{OUTPUT_DIR}/*.json").map do |file|
48
+ JSON.parse(File.read(file))
49
+ end
52
50
 
53
51
  # Extract the JSON profile structures from the full results.
54
52
  profile_blocks = outputs.map { |output| output.fetch('profile') }
@@ -88,8 +86,8 @@ module StableProfile
88
86
 
89
87
  example = record.fetch(:example)
90
88
 
91
- puts " #{example['full_description']}"
92
- puts " #{record[:average_time]} seconds".bold.ljust(27) + " (N=#{record[:run_times].size})".ljust(7) + " #{example['file_path']}:#{example['line_number']}"
89
+ puts " #{example['full_description']}".colorize(:light_black)
90
+ puts bold(" #{record[:average_time]} seconds").ljust(27) + " (N=#{record[:run_times].size})".ljust(7) + " #{example['file_path']}:#{example['line_number']}"
93
91
  end
94
92
 
95
93
  puts
@@ -102,8 +100,8 @@ module StableProfile
102
100
 
103
101
  group = record.fetch(:group)
104
102
 
105
- puts " #{group['description']}"
106
- puts " #{record[:average_time]} seconds".bold.ljust(27) + " (N=#{record[:run_times].size})".ljust(7) + " #{group['location']}"
103
+ puts " #{group['description']}".colorize(:light_black)
104
+ puts bold(" #{record[:average_time]} seconds").ljust(27) + " (N=#{record[:run_times].size})".ljust(7) + " #{group['location']}"
107
105
  end
108
106
  end
109
107
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stable_profile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-31 00:00:00.000000000 Z
11
+ date: 2023-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: ruby-progressbar
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +94,11 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: 3.12.0
83
- description: Repeatedly run --profile, averaging the results.
97
+ description: 'Solves a quirk of rspec --profile in some code bases: result vary with
98
+ every random spec ordering. This seems to be due to differences in dependency load
99
+ order, class initialization, and test server startup. This lib runs rspec --profile
100
+ many times, averaging the results to always give the same (stable) and meaningful
101
+ result.'
84
102
  email:
85
103
  - robb@public.law
86
104
  executables: