benchable 0.1.0 → 0.2.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: 7c0476be4799e0045af57ce9be72401caf7acc7a0de12f0288d02b5c0dac1be5
4
- data.tar.gz: edfd89e36cbb1e2d63d16d20f2b40ae8c441580d97bee9bdd5fc4710afd62bd5
3
+ metadata.gz: ea8211a8067a809843da4eb4597f8410b066885729d16a09a5ee5996fb3e2af9
4
+ data.tar.gz: 2fa2084edce688c7184591c2ce01b4b4ff7bedb7212a9a4dbbc99f6e3b80ac0b
5
5
  SHA512:
6
- metadata.gz: 46ce119b1f4d4991e1e022b3b79449b857d60cdc635afa435983b3cab2a1719a5cf6586faa6f2685627592fae6badff8e0110e254a99067183e89721788dd899
7
- data.tar.gz: dbf498e5e3fc4aa94846f0cb4e701bf97f456e68c4bd68af5bb577338228efa56328ef1676cc1f55369874026c71d70e0f2b7c0c75026c87973761fae10180cc
6
+ metadata.gz: a1e2f7cb8f1ef3165917b10dee6701ee8397b1b5d65e2d859f43fb0fab3af20858d2b86362cef964282e4978e551e7287ab1927f072c05c8b05620790c3d7e0c
7
+ data.tar.gz: 6a1c2a65c2895b296051a4daaa5cc2b20972e747678582fe3459db0f705b9dd558d1de1aa1982725bd3235be462c41732156548405a2b4bf8a54f4e9adfb12c2
@@ -12,6 +12,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
12
12
  <!-- ### Removed -->
13
13
  ---
14
14
 
15
+ ## [0.2.0] - 2020-10-23
16
+
17
+ ### Added
18
+ - Support for `Benchmark.memory` via [benchmark-memory](https://github.com/michaelherold/benchmark-memory).
19
+
20
+ [unreleased]: https://github.com/MatheusRich/benchable/compare/v0.2.0...HEAD
21
+ [0.2.0]: https://github.com/MatheusRich/benchable/releases/tag/v0.2.0
22
+
15
23
  ## [0.1.0] - 2020-08-16
16
24
 
17
25
  ### Added
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- benchable (0.1.0)
4
+ benchable (0.2.0)
5
5
  benchmark-ips (~> 2.8, >= 2.8.2)
6
+ benchmark-memory (~> 0.1.2)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -10,7 +11,9 @@ GEM
10
11
  ast (2.4.1)
11
12
  backport (1.1.2)
12
13
  benchmark (0.1.0)
13
- benchmark-ips (2.8.2)
14
+ benchmark-ips (2.8.3)
15
+ benchmark-memory (0.1.2)
16
+ memory_profiler (~> 0.9)
14
17
  coderay (1.1.3)
15
18
  diff-lcs (1.4.4)
16
19
  docile (1.3.2)
@@ -37,6 +40,7 @@ GEM
37
40
  rb-inotify (~> 0.9, >= 0.9.10)
38
41
  lumberjack (1.2.7)
39
42
  maruku (0.7.3)
43
+ memory_profiler (0.9.14)
40
44
  method_source (1.0.0)
41
45
  mini_portile2 (2.4.0)
42
46
  nenv (0.3.0)
data/README.md CHANGED
@@ -64,7 +64,7 @@ end
64
64
  > We've used `Array#dup` in the example above to prevent the benchmarks for modifying the original array
65
65
 
66
66
  ### Benchmark types
67
- There are 3 benchmark types available: `bm`, `bmbm` and `ips`. You can specify it by passing the type as a symbol on the `Benchable.bench` method. The default type is `bm`.
67
+ There are 4 benchmark types 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
68
 
69
69
  ```ruby
70
70
  Benchable.bench(:bm) do
@@ -78,6 +78,10 @@ end
78
78
  Benchable.bench(:ips) do
79
79
  # ...
80
80
  end
81
+
82
+ Benchable.bench(:memory) do
83
+ # ...
84
+ end
81
85
  ```
82
86
 
83
87
  Given an invalid benchmark type, Benchable will raise an exception.
@@ -91,7 +95,7 @@ end
91
95
  ### Benchmark options
92
96
  You can provide benchmark options by passing a hash to the `Benchable.bench` method.
93
97
 
94
- ### Options for `Benchmark.bm` and `Benchmark.bmbm`
98
+ #### Options for `Benchmark.bm` and `Benchmark.bmbm`
95
99
  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`.
96
100
 
97
101
  ```ruby
@@ -100,12 +104,12 @@ Benchable.bench(width: 25) do
100
104
  end
101
105
  ```
102
106
 
103
- ### Options for `Benchmark::IPS`
104
- If you're using, you can pass any option accepted by `Benchmark::IPS` `config` method.
107
+ #### Options for `Benchmark::IPS`
108
+ If you're using `::IPS`, you can pass any option accepted by `Benchmark::IPS`' `config` method.
105
109
 
106
110
  ```ruby
107
111
  Benchable.bench(:ips, time: 5, warmup: 2) do
108
- #
112
+ # ...
109
113
  end
110
114
  # Output:
111
115
  # Warming up --------------------------------------
@@ -116,6 +120,18 @@ end
116
120
  # Sort! 2.120 (± 0.0%) i/s - 11.000 in 5.189772s
117
121
  ```
118
122
 
123
+ #### Options for `Benchmark::Memory`
124
+ You can pass [any option accepted](https://github.com/michaelherold/benchmark-memory#options) by `Benchmark::Memory`.
125
+
126
+ ```ruby
127
+ Benchable.bench(:memory, quiet: true) do
128
+ # ...
129
+ end
130
+ # Output:
131
+ # => #<Benchmark::Memory::Report:0x0000558cdfdbc498 ...>
132
+
133
+ ```
134
+
119
135
  ## Development
120
136
 
121
137
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -128,7 +144,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Matheu
128
144
 
129
145
 
130
146
  ## Acknowledgments
131
- Thanks [@naomik](https://github.com/naomik) for building the bease idea for this in [his gist](https://gist.github.com/naomik/6012505)!
147
+ Thanks [@naomik](https://github.com/naomik) for building the base idea for this in [his gist](https://gist.github.com/naomik/6012505)!
132
148
 
133
149
  ## License
134
150
 
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ['lib']
29
29
 
30
30
  spec.add_runtime_dependency 'benchmark-ips', '~> 2.8', '>= 2.8.2'
31
+ spec.add_runtime_dependency 'benchmark-memory', '~> 0.1.2'
31
32
  end
@@ -2,11 +2,12 @@
2
2
 
3
3
  require 'benchmark'
4
4
  require 'benchmark/ips'
5
+ require 'benchmark/memory'
5
6
 
6
7
  module Benchable
7
8
  class Benchmark
8
9
  DEFAULT_WIDTH = 20
9
- BENCHMARK_TYPES = %i[bm bmbm ips].freeze
10
+ BENCHMARK_TYPES = %i[bm bmbm ips memory].freeze
10
11
 
11
12
  def initialize(benchmark_type, options = {})
12
13
  @benchmark_type = benchmark_type
@@ -63,9 +64,17 @@ module Benchable
63
64
  end
64
65
 
65
66
  def benchmark(&block)
67
+ ::Benchmark.public_send(*benchmark_args, &block)
68
+ end
69
+
70
+ def benchmark_args
66
71
  width = options[:width] || DEFAULT_WIDTH
67
72
 
68
- ::Benchmark.public_send(benchmark_type, width, &block)
73
+ args = [benchmark_type]
74
+ args << width unless benchmark_type == :memory
75
+ args << options if benchmark_type == :memory
76
+
77
+ args
69
78
  end
70
79
  end
71
80
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Benchable
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matheus Richard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-16 00:00:00.000000000 Z
11
+ date: 2020-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.8.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: benchmark-memory
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.1.2
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.1.2
33
47
  description:
34
48
  email:
35
49
  - matheusrichardt@gmail.com