stable_profile 0.4.0 → 0.5.0
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.rb +17 -19
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdc1251ab06ef89ebd5900e3159d0783f45c283f47e3e8d536c2f3d264c0f482
|
4
|
+
data.tar.gz: c46a33e840de54c00ff9be23cef7fa31a95340e2ac8b7866e23e3b0733f54ad4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bd390ac4a17735e2d4fab46196c1bce4a3152f1f0b1e958e58d15e03a4b6f83e437fdb8c25fb586f68fcca53b5949201ed10b92ad9076b6417cd948efdc2ab0
|
7
|
+
data.tar.gz: 2b21c63b395890dac6b1a7f4afef4efda08bb727f1ac339ef2899d718b26a2f06a013c4638ad3edbaa4669e26e2e8298becec6c9b17c6f65cc661a4570a078ab
|
data/lib/stable_profile.rb
CHANGED
@@ -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
|
-
|
28
|
-
|
29
|
-
|
22
|
+
ITERATIONS = 20
|
23
|
+
MINIMUM_SAMPLE_SIZE = ITERATIONS * 0.75
|
24
|
+
DECIMAL_PLACES = 4
|
30
25
|
|
31
|
-
|
32
|
-
MINIMUM_SAMPLE_SIZE = ITERATIONS / 2
|
33
|
-
DECIMAL_PLACES = 4
|
26
|
+
OUTPUT_DIR = 'tmp/stable_profile'
|
34
27
|
|
35
|
-
|
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
|
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
|
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".
|
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".
|
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
|
+
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-
|
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:
|
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:
|