benchable 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests-and-linter.yml +4 -4
- data/CHANGELOG.md +33 -4
- data/Gemfile +8 -8
- data/Gemfile.lock +65 -55
- data/Guardfile +8 -8
- data/README.md +36 -7
- data/Rakefile +2 -2
- data/benchable.gemspec +17 -17
- data/lib/benchable/benchmark.rb +15 -9
- data/lib/benchable/version.rb +1 -1
- data/lib/benchable.rb +17 -8
- metadata +8 -9
- data/.rubocop.yml +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8cc2eab98fd2843682811029e789c3d50f28cef0cab9e607936700579e65cf6
|
4
|
+
data.tar.gz: 38f5b868dece18aaf0567603346ff9677b998486c12236a6915cfbedac0ead13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 555bcfbff720e4f8044504d7055da3b265f3adf0ad73ba8039dd6f3cc31de82cce6932ce100934ddc72356c2e59021334fa9f83eab31f3e9d090f5d9d88d7aed
|
7
|
+
data.tar.gz: dbc3b735b5400fa4cd948bc4535cb2a5d2998463b8411b72cd569171dff21058bd89bb6d9c73a2f58d5cd3fdfe4470fbc1d636832c3fa5bbf00b45075afefbb1
|
@@ -11,12 +11,12 @@ jobs:
|
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
strategy:
|
13
13
|
matrix:
|
14
|
-
ruby: [2.
|
14
|
+
ruby: [2.6, 2.7, '3.0']
|
15
15
|
|
16
16
|
steps:
|
17
17
|
- uses: actions/checkout@v2
|
18
18
|
- name: Set up Ruby ${{ matrix.ruby }}
|
19
|
-
uses:
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
20
|
with:
|
21
21
|
ruby-version: ${{ matrix.ruby }}
|
22
22
|
- name: Build and test with Rake
|
@@ -24,5 +24,5 @@ jobs:
|
|
24
24
|
gem install bundler
|
25
25
|
bundle install --jobs 4 --retry 3
|
26
26
|
bundle exec rake
|
27
|
-
- name:
|
28
|
-
run: bundle exec
|
27
|
+
- name: Linter
|
28
|
+
run: bundle exec standardrb
|
data/CHANGELOG.md
CHANGED
@@ -6,9 +6,36 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
|
+
---
|
10
|
+
|
11
|
+
## [0.3.0] - 2021-09-09
|
12
|
+
|
13
|
+
### Added
|
14
|
+
|
15
|
+
- Allow running multiple benchmarks at once:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Benchable.bench(:ips, :memory) do
|
19
|
+
setup do
|
20
|
+
@array = (1..1000000).map { rand }
|
21
|
+
end
|
22
|
+
|
23
|
+
bench 'sort' do
|
24
|
+
@array.dup.sort
|
25
|
+
end
|
26
|
+
|
27
|
+
bench 'sort!' do
|
28
|
+
@array.dup.sort!
|
29
|
+
end
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
- Compare benchmarks after running them 🤦♂️.
|
34
|
+
|
35
|
+
### Changed
|
36
|
+
|
37
|
+
- Require >= Ruby 2.6.
|
9
38
|
|
10
|
-
<!-- ### Added -->
|
11
|
-
<!-- ### Changed -->
|
12
39
|
<!-- ### Removed -->
|
13
40
|
---
|
14
41
|
|
@@ -25,5 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
25
52
|
### Added
|
26
53
|
- Support for `Benchmark.bm`, `Benchmark.bmbm` and `Benchmark.ips`.
|
27
54
|
|
28
|
-
[unreleased]: https://github.com/MatheusRich/benchable/compare/v0.
|
29
|
-
[0.1.0]: https://github.com/MatheusRich/benchable/releases/tag/v0.1.0
|
55
|
+
[unreleased]: https://github.com/MatheusRich/benchable/compare/v0.3.0...HEAD
|
56
|
+
[0.1.0]: https://github.com/MatheusRich/benchable/releases/tag/v0.1.0
|
57
|
+
[0.2.0]: https://github.com/MatheusRich/benchable/releases/tag/v0.2.0
|
58
|
+
[0.3.0]: https://github.com/MatheusRich/benchable/releases/tag/v0.3.0
|
data/Gemfile
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
3
|
+
source "https://rubygems.org"
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in benchable.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem
|
9
|
-
gem
|
10
|
-
gem
|
11
|
-
gem
|
12
|
-
gem
|
13
|
-
gem
|
14
|
-
gem
|
8
|
+
gem "guard-rspec", require: false
|
9
|
+
gem "rake", "~> 12.0"
|
10
|
+
gem "rspec", "~> 3.0"
|
11
|
+
gem "standard", "~> 1.3.0"
|
12
|
+
gem "simplecov", "~> 0.18.5", require: false
|
13
|
+
gem "solargraph", "~> 0.39"
|
14
|
+
gem "yard", "~> 0.9.25"
|
data/Gemfile.lock
CHANGED
@@ -8,25 +8,25 @@ PATH
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
ast (2.4.
|
12
|
-
backport (1.
|
13
|
-
benchmark (0.1.
|
14
|
-
benchmark-ips (2.
|
11
|
+
ast (2.4.2)
|
12
|
+
backport (1.2.0)
|
13
|
+
benchmark (0.1.1)
|
14
|
+
benchmark-ips (2.9.1)
|
15
15
|
benchmark-memory (0.1.2)
|
16
16
|
memory_profiler (~> 0.9)
|
17
17
|
coderay (1.1.3)
|
18
18
|
diff-lcs (1.4.4)
|
19
|
-
docile (1.
|
19
|
+
docile (1.4.0)
|
20
20
|
e2mmap (0.1.0)
|
21
|
-
ffi (1.
|
22
|
-
formatador (0.
|
23
|
-
guard (2.
|
21
|
+
ffi (1.15.4)
|
22
|
+
formatador (0.3.0)
|
23
|
+
guard (2.18.0)
|
24
24
|
formatador (>= 0.2.4)
|
25
25
|
listen (>= 2.7, < 4.0)
|
26
26
|
lumberjack (>= 1.0.12, < 2.0)
|
27
27
|
nenv (~> 0.1)
|
28
28
|
notiffany (~> 0.0)
|
29
|
-
pry (>= 0.
|
29
|
+
pry (>= 0.13.0)
|
30
30
|
shellany (~> 0.0)
|
31
31
|
thor (>= 0.18.1)
|
32
32
|
guard-compat (1.2.1)
|
@@ -35,85 +35,95 @@ GEM
|
|
35
35
|
guard-compat (~> 1.1)
|
36
36
|
rspec (>= 2.99.0, < 4.0)
|
37
37
|
jaro_winkler (1.5.4)
|
38
|
-
|
38
|
+
kramdown (2.3.1)
|
39
|
+
rexml
|
40
|
+
kramdown-parser-gfm (1.1.0)
|
41
|
+
kramdown (~> 2.0)
|
42
|
+
listen (3.7.0)
|
39
43
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
40
44
|
rb-inotify (~> 0.9, >= 0.9.10)
|
41
|
-
lumberjack (1.2.
|
42
|
-
maruku (0.7.3)
|
45
|
+
lumberjack (1.2.8)
|
43
46
|
memory_profiler (0.9.14)
|
44
47
|
method_source (1.0.0)
|
45
|
-
mini_portile2 (2.
|
48
|
+
mini_portile2 (2.6.1)
|
46
49
|
nenv (0.3.0)
|
47
|
-
nokogiri (1.
|
48
|
-
mini_portile2 (~> 2.
|
50
|
+
nokogiri (1.12.4)
|
51
|
+
mini_portile2 (~> 2.6.1)
|
52
|
+
racc (~> 1.4)
|
49
53
|
notiffany (0.1.3)
|
50
54
|
nenv (~> 0.1)
|
51
55
|
shellany (~> 0.0)
|
52
|
-
parallel (1.
|
53
|
-
parser (
|
56
|
+
parallel (1.20.1)
|
57
|
+
parser (3.0.2.0)
|
54
58
|
ast (~> 2.4.1)
|
55
|
-
pry (0.
|
59
|
+
pry (0.14.1)
|
56
60
|
coderay (~> 1.1)
|
57
61
|
method_source (~> 1.0)
|
62
|
+
racc (1.5.2)
|
58
63
|
rainbow (3.0.0)
|
59
64
|
rake (12.3.3)
|
60
|
-
rb-fsevent (0.
|
65
|
+
rb-fsevent (0.11.0)
|
61
66
|
rb-inotify (0.10.1)
|
62
67
|
ffi (~> 1.0)
|
63
|
-
regexp_parser (1.
|
68
|
+
regexp_parser (2.1.1)
|
64
69
|
reverse_markdown (2.0.0)
|
65
70
|
nokogiri
|
66
|
-
rexml (3.2.
|
67
|
-
rspec (3.
|
68
|
-
rspec-core (~> 3.
|
69
|
-
rspec-expectations (~> 3.
|
70
|
-
rspec-mocks (~> 3.
|
71
|
-
rspec-core (3.
|
72
|
-
rspec-support (~> 3.
|
73
|
-
rspec-expectations (3.
|
71
|
+
rexml (3.2.5)
|
72
|
+
rspec (3.10.0)
|
73
|
+
rspec-core (~> 3.10.0)
|
74
|
+
rspec-expectations (~> 3.10.0)
|
75
|
+
rspec-mocks (~> 3.10.0)
|
76
|
+
rspec-core (3.10.1)
|
77
|
+
rspec-support (~> 3.10.0)
|
78
|
+
rspec-expectations (3.10.1)
|
74
79
|
diff-lcs (>= 1.2.0, < 2.0)
|
75
|
-
rspec-support (~> 3.
|
76
|
-
rspec-mocks (3.
|
80
|
+
rspec-support (~> 3.10.0)
|
81
|
+
rspec-mocks (3.10.2)
|
77
82
|
diff-lcs (>= 1.2.0, < 2.0)
|
78
|
-
rspec-support (~> 3.
|
79
|
-
rspec-support (3.
|
80
|
-
rubocop (
|
83
|
+
rspec-support (~> 3.10.0)
|
84
|
+
rspec-support (3.10.2)
|
85
|
+
rubocop (1.20.0)
|
81
86
|
parallel (~> 1.10)
|
82
|
-
parser (>=
|
87
|
+
parser (>= 3.0.0.0)
|
83
88
|
rainbow (>= 2.2.2, < 4.0)
|
84
|
-
regexp_parser (>= 1.
|
89
|
+
regexp_parser (>= 1.8, < 3.0)
|
85
90
|
rexml
|
86
|
-
rubocop-ast (>=
|
91
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
87
92
|
ruby-progressbar (~> 1.7)
|
88
|
-
unicode-display_width (>= 1.4.0, <
|
89
|
-
rubocop-ast (
|
90
|
-
parser (>=
|
91
|
-
rubocop-
|
92
|
-
rubocop (>=
|
93
|
-
|
93
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
94
|
+
rubocop-ast (1.11.0)
|
95
|
+
parser (>= 3.0.1.1)
|
96
|
+
rubocop-performance (1.11.5)
|
97
|
+
rubocop (>= 1.7.0, < 2.0)
|
98
|
+
rubocop-ast (>= 0.4.0)
|
99
|
+
ruby-progressbar (1.11.0)
|
94
100
|
shellany (0.0.1)
|
95
101
|
simplecov (0.18.5)
|
96
102
|
docile (~> 1.1)
|
97
103
|
simplecov-html (~> 0.11)
|
98
|
-
simplecov-html (0.12.
|
99
|
-
solargraph (0.
|
100
|
-
backport (~> 1.
|
104
|
+
simplecov-html (0.12.3)
|
105
|
+
solargraph (0.43.0)
|
106
|
+
backport (~> 1.2)
|
101
107
|
benchmark
|
102
108
|
bundler (>= 1.17.2)
|
109
|
+
diff-lcs (~> 1.4)
|
103
110
|
e2mmap
|
104
111
|
jaro_winkler (~> 1.5)
|
105
|
-
|
106
|
-
|
107
|
-
parser (~>
|
112
|
+
kramdown (~> 2.3)
|
113
|
+
kramdown-parser-gfm (~> 1.1)
|
114
|
+
parser (~> 3.0)
|
108
115
|
reverse_markdown (>= 1.0.5, < 3)
|
109
|
-
rubocop (
|
116
|
+
rubocop (>= 0.52)
|
110
117
|
thor (~> 1.0)
|
111
118
|
tilt (~> 2.0)
|
112
119
|
yard (~> 0.9, >= 0.9.24)
|
113
|
-
|
120
|
+
standard (1.3.0)
|
121
|
+
rubocop (= 1.20.0)
|
122
|
+
rubocop-performance (= 1.11.5)
|
123
|
+
thor (1.1.0)
|
114
124
|
tilt (2.0.10)
|
115
|
-
unicode-display_width (
|
116
|
-
yard (0.9.
|
125
|
+
unicode-display_width (2.0.0)
|
126
|
+
yard (0.9.26)
|
117
127
|
|
118
128
|
PLATFORMS
|
119
129
|
ruby
|
@@ -123,10 +133,10 @@ DEPENDENCIES
|
|
123
133
|
guard-rspec
|
124
134
|
rake (~> 12.0)
|
125
135
|
rspec (~> 3.0)
|
126
|
-
rubocop (~> 0.89.1)
|
127
|
-
rubocop-rspec (~> 1.42)
|
128
136
|
simplecov (~> 0.18.5)
|
129
|
-
solargraph (~> 0.39
|
137
|
+
solargraph (~> 0.39)
|
138
|
+
standard (~> 1.3.0)
|
139
|
+
yard (~> 0.9.25)
|
130
140
|
|
131
141
|
BUNDLED WITH
|
132
142
|
2.1.4
|
data/Guardfile
CHANGED
@@ -26,8 +26,8 @@
|
|
26
26
|
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
27
27
|
# * 'just' rspec: 'rspec'
|
28
28
|
|
29
|
-
guard :rspec, cmd:
|
30
|
-
require
|
29
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
30
|
+
require "guard/rspec/dsl"
|
31
31
|
dsl = Guard::RSpec::Dsl.new(self)
|
32
32
|
|
33
33
|
# Feel free to open issues for suggestions and improvements
|
@@ -56,17 +56,17 @@ guard :rspec, cmd: 'bundle exec rspec' do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
# Rails config changes
|
59
|
-
watch(rails.spec_helper)
|
60
|
-
watch(rails.routes)
|
61
|
-
watch(rails.app_controller)
|
59
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
60
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
61
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
62
62
|
|
63
63
|
# Capybara features specs
|
64
|
-
watch(rails.view_dirs)
|
65
|
-
watch(rails.layouts)
|
64
|
+
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
|
65
|
+
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
|
66
66
|
|
67
67
|
# Turnip features and steps
|
68
68
|
watch(%r{^spec/acceptance/(.+)\.feature$})
|
69
69
|
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
70
|
-
Dir[File.join("**/#{m[1]}.feature")][0] ||
|
70
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
71
71
|
end
|
72
72
|
end
|
data/README.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
<p align="center">
|
2
|
+
<h1 align="center">Benchable</h1>
|
3
|
+
|
4
|
+
<p align="center">
|
5
|
+
<i>Write benchmarks without the hassle.</i>
|
6
|
+
<br>
|
7
|
+
<br>
|
8
|
+
<img src="https://img.shields.io/gem/v/benchable">
|
9
|
+
<img src="https://img.shields.io/gem/dt/benchable">
|
10
|
+
<img src="https://github.com/MatheusRich/benchable/workflows/Ruby/badge.svg">
|
11
|
+
<a href="https://github.com/MatheusRich/benchable/blob/master/LICENSE">
|
12
|
+
<img src="https://img.shields.io/github/license/MatheusRich/benchable.svg" alt="License">
|
13
|
+
</a>
|
14
|
+
</p>
|
15
|
+
</p>
|
4
16
|
|
5
17
|
## Installation
|
6
18
|
|
@@ -19,13 +31,15 @@ Or install it yourself as:
|
|
19
31
|
$ gem install benchable
|
20
32
|
|
21
33
|
## Usage
|
34
|
+
|
22
35
|
### Basic usage
|
36
|
+
|
23
37
|
Use the method `Benchable.bench` to declare a benchmark. Write each benchmark case with the `bench` method. The benchmark will run automatically.
|
24
38
|
|
25
39
|
```ruby
|
26
40
|
Benchable.bench do
|
27
41
|
bench 'sort' do
|
28
|
-
(1..1000000).map { rand }.sort
|
42
|
+
(1..1000000).map { rand }.sort
|
29
43
|
end
|
30
44
|
|
31
45
|
bench 'sort!' do
|
@@ -49,7 +63,7 @@ Benchable.bench do
|
|
49
63
|
end
|
50
64
|
|
51
65
|
bench 'sort' do
|
52
|
-
@array.dup.sort
|
66
|
+
@array.dup.sort
|
53
67
|
end
|
54
68
|
|
55
69
|
bench 'sort!' do
|
@@ -61,10 +75,12 @@ end
|
|
61
75
|
# Sort 0.400133 0.011995 0.412128 ( 0.412339)
|
62
76
|
# Sort! 0.388636 0.003980 0.392616 ( 0.393054)
|
63
77
|
```
|
78
|
+
|
64
79
|
> We've used `Array#dup` in the example above to prevent the benchmarks for modifying the original array
|
65
80
|
|
66
81
|
### Benchmark types
|
67
|
-
|
82
|
+
|
83
|
+
Four benchmark types are available: `bm`, `bmbm`, `ips` and `memory`. You can specify the type by passing it as a symbol on the `Benchable.bench` method. The default type is `bm`.
|
68
84
|
|
69
85
|
```ruby
|
70
86
|
Benchable.bench(:bm) do
|
@@ -84,7 +100,16 @@ Benchable.bench(:memory) do
|
|
84
100
|
end
|
85
101
|
```
|
86
102
|
|
103
|
+
You can also run multiple benchmarks at once:
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
Benchable.bench(:ips, :memory) do
|
107
|
+
# ...
|
108
|
+
end
|
109
|
+
```
|
110
|
+
|
87
111
|
Given an invalid benchmark type, Benchable will raise an exception.
|
112
|
+
|
88
113
|
```ruby
|
89
114
|
Benchable.bench(:invalid) do
|
90
115
|
# ...
|
@@ -93,9 +118,11 @@ end
|
|
93
118
|
```
|
94
119
|
|
95
120
|
### Benchmark options
|
121
|
+
|
96
122
|
You can provide benchmark options by passing a hash to the `Benchable.bench` method.
|
97
123
|
|
98
124
|
#### Options for `Benchmark.bm` and `Benchmark.bmbm`
|
125
|
+
|
99
126
|
On `bm` and `bmbm` benchmarks the only available option is `width`, which specifies the leading spaces for labels on each line. The default width is `20`.
|
100
127
|
|
101
128
|
```ruby
|
@@ -105,6 +132,7 @@ end
|
|
105
132
|
```
|
106
133
|
|
107
134
|
#### Options for `Benchmark::IPS`
|
135
|
+
|
108
136
|
If you're using `::IPS`, you can pass any option accepted by `Benchmark::IPS`' `config` method.
|
109
137
|
|
110
138
|
```ruby
|
@@ -121,6 +149,7 @@ end
|
|
121
149
|
```
|
122
150
|
|
123
151
|
#### Options for `Benchmark::Memory`
|
152
|
+
|
124
153
|
You can pass [any option accepted](https://github.com/michaelherold/benchmark-memory#options) by `Benchmark::Memory`.
|
125
154
|
|
126
155
|
```ruby
|
@@ -142,8 +171,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
142
171
|
|
143
172
|
Bug reports and pull requests are welcome on GitHub at https://github.com/MatheusRich/benchable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/MatheusRich/benchable/blob/master/CODE_OF_CONDUCT.md).
|
144
173
|
|
145
|
-
|
146
174
|
## Acknowledgments
|
175
|
+
|
147
176
|
Thanks [@naomik](https://github.com/naomik) for building the base idea for this in [his gist](https://gist.github.com/naomik/6012505)!
|
148
177
|
|
149
178
|
## License
|
data/Rakefile
CHANGED
data/benchable.gemspec
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "lib/benchable/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
6
|
+
spec.name = "benchable"
|
7
|
+
spec.version = Benchable::VERSION
|
8
|
+
spec.authors = ["Matheus Richard"]
|
9
|
+
spec.email = ["matheusrichardt@gmail.com"]
|
10
10
|
|
11
|
-
spec.summary
|
11
|
+
spec.summary = "Write benchmarks without the hassle"
|
12
12
|
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
13
|
+
spec.homepage = "https://github.com/MatheusRich/benchable"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
16
16
|
|
17
|
-
spec.metadata[
|
18
|
-
spec.metadata[
|
19
|
-
spec.metadata[
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/MatheusRich/benchable"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/MatheusRich/benchable/blob/master/CHANGELOG.md"
|
20
20
|
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
22
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
23
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
24
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
25
|
end
|
26
|
-
spec.bindir
|
27
|
-
spec.executables
|
28
|
-
spec.require_paths = [
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
-
spec.add_runtime_dependency
|
31
|
-
spec.add_runtime_dependency
|
30
|
+
spec.add_runtime_dependency "benchmark-ips", "~> 2.8", ">= 2.8.2"
|
31
|
+
spec.add_runtime_dependency "benchmark-memory", "~> 0.1.2"
|
32
32
|
end
|
data/lib/benchable/benchmark.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "benchmark"
|
4
|
+
require "benchmark/ips"
|
5
|
+
require "benchmark/memory"
|
6
6
|
|
7
7
|
module Benchable
|
8
|
+
# Main class to perform benchmarks.
|
9
|
+
#
|
10
|
+
# Use the method Benchable.bench to declare a benchmark.
|
8
11
|
class Benchmark
|
9
12
|
DEFAULT_WIDTH = 20
|
10
13
|
BENCHMARK_TYPES = %i[bm bmbm ips memory].freeze
|
@@ -24,7 +27,8 @@ module Benchable
|
|
24
27
|
define_method(method_name_for(name), &block)
|
25
28
|
end
|
26
29
|
|
27
|
-
def setup
|
30
|
+
def setup
|
31
|
+
end
|
28
32
|
|
29
33
|
def run
|
30
34
|
setup
|
@@ -36,7 +40,7 @@ module Benchable
|
|
36
40
|
end
|
37
41
|
|
38
42
|
private_class_method def self.method_name_for(name)
|
39
|
-
"bench_#{name.to_s.
|
43
|
+
"bench_#{name.to_s.tr(" ", "_").downcase}"
|
40
44
|
end
|
41
45
|
|
42
46
|
private
|
@@ -48,19 +52,21 @@ module Benchable
|
|
48
52
|
end
|
49
53
|
|
50
54
|
def run_benchmark
|
51
|
-
benchmark do |
|
52
|
-
|
55
|
+
benchmark do |b|
|
56
|
+
b.config(**options) if benchmark_type == :ips
|
53
57
|
|
54
58
|
cases.each do |benchmark_case|
|
55
|
-
|
59
|
+
b.report(name_for(benchmark_case)) do
|
56
60
|
method(benchmark_case).call
|
57
61
|
end
|
58
62
|
end
|
63
|
+
|
64
|
+
b.compare! if b.respond_to? :compare!
|
59
65
|
end
|
60
66
|
end
|
61
67
|
|
62
68
|
def name_for(benchmark_case)
|
63
|
-
benchmark_case.to_s.gsub(
|
69
|
+
benchmark_case.to_s.gsub("bench_", "").tr("_", " ").capitalize
|
64
70
|
end
|
65
71
|
|
66
72
|
def benchmark(&block)
|
data/lib/benchable/version.rb
CHANGED
data/lib/benchable.rb
CHANGED
@@ -1,18 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
3
|
+
require_relative "benchable/benchmark"
|
4
|
+
require_relative "benchable/version"
|
5
5
|
|
6
|
+
# Benchable is used for automating benchmarks
|
6
7
|
module Benchable
|
7
8
|
class Error < StandardError; end
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
class << self
|
11
|
+
def build(type = :bm, **options, &block)
|
12
|
+
bench_class = Class.new(Benchmark, &block)
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
bench_class.new(type, **options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def bench(*types, **options, &block)
|
18
|
+
types << :bm if types.empty?
|
14
19
|
|
15
|
-
|
16
|
-
|
20
|
+
if options.empty?
|
21
|
+
types.map { |type| build(type, &block).run }
|
22
|
+
else
|
23
|
+
types.map { |type| build(type, **options, &block).run }
|
24
|
+
end
|
25
|
+
end
|
17
26
|
end
|
18
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: benchable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matheus Richard
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 0.1.2
|
47
|
-
description:
|
47
|
+
description:
|
48
48
|
email:
|
49
49
|
- matheusrichardt@gmail.com
|
50
50
|
executables: []
|
@@ -54,7 +54,6 @@ files:
|
|
54
54
|
- ".github/workflows/tests-and-linter.yml"
|
55
55
|
- ".gitignore"
|
56
56
|
- ".rspec"
|
57
|
-
- ".rubocop.yml"
|
58
57
|
- CHANGELOG.md
|
59
58
|
- CODE_OF_CONDUCT.md
|
60
59
|
- Gemfile
|
@@ -76,7 +75,7 @@ metadata:
|
|
76
75
|
homepage_uri: https://github.com/MatheusRich/benchable
|
77
76
|
source_code_uri: https://github.com/MatheusRich/benchable
|
78
77
|
changelog_uri: https://github.com/MatheusRich/benchable/blob/master/CHANGELOG.md
|
79
|
-
post_install_message:
|
78
|
+
post_install_message:
|
80
79
|
rdoc_options: []
|
81
80
|
require_paths:
|
82
81
|
- lib
|
@@ -84,15 +83,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
83
|
requirements:
|
85
84
|
- - ">="
|
86
85
|
- !ruby/object:Gem::Version
|
87
|
-
version: 2.
|
86
|
+
version: 2.6.0
|
88
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
88
|
requirements:
|
90
89
|
- - ">="
|
91
90
|
- !ruby/object:Gem::Version
|
92
91
|
version: '0'
|
93
92
|
requirements: []
|
94
|
-
rubygems_version: 3.
|
95
|
-
signing_key:
|
93
|
+
rubygems_version: 3.2.25
|
94
|
+
signing_key:
|
96
95
|
specification_version: 4
|
97
96
|
summary: Write benchmarks without the hassle
|
98
97
|
test_files: []
|
data/.rubocop.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require:
|
2
|
-
- rubocop-rspec
|
3
|
-
|
4
|
-
AllCops:
|
5
|
-
NewCops: enable
|
6
|
-
|
7
|
-
Layout/LineLength:
|
8
|
-
Max: 120
|
9
|
-
|
10
|
-
Metrics/BlockLength:
|
11
|
-
Exclude:
|
12
|
-
- "spec/**/*"
|
13
|
-
- "Guardfile"
|
14
|
-
|
15
|
-
Style/Documentation:
|
16
|
-
Enabled: false
|
17
|
-
|
18
|
-
Style/DocumentationMethod:
|
19
|
-
Enabled: false
|