avgbm 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +2 -0
- data/avgbm.gemspec +23 -0
- data/lib/avgbm.rb +47 -0
- data/lib/avgbm/version.rb +3 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 867d04ec632d9b4da54d5d62a92e8937a431ec6c
|
4
|
+
data.tar.gz: 7a311a8045d48394aadf388c802b5a8d2786cf74
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d2a2c368cb7d66a35a2f9b934e6364f3a2e53c916a02a26c1f80906d6f3ef5c770888b952f38a972bc7e1bc99db64f57f85140b5fe156a2a5e1b1d27048d5e2
|
7
|
+
data.tar.gz: 42ebf2b2f6870bf257b7e17781f5079d0a9ae7d7caf2784b432f7d3be96d88489ca3c566b2bd138055b9b771a15f816a72829dec7b4933248278b775ead4d285
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Girish S
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Avgbm
|
2
|
+
|
3
|
+
Adds `avgbm` method to Ruby `Benchmark` std lib, that discards highest/lowest times and averages the remaining results.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'avgbm'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install avgbm
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
The first param is number of times to run each code block (defaults to and minimum is 5).
|
24
|
+
Second param is the label width for printing.
|
25
|
+
It discards about 20% highest/lowest times and averages the remaining 60% results.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
Benchmark.avgbm(10) do |x|
|
29
|
+
x.report("pluck") { Node.pluck(:id, :title) }
|
30
|
+
x.report("select") { Node.select(:id, :title).to_a }
|
31
|
+
x.report("as_json") { Node.select(:id, :title).as_json }
|
32
|
+
end
|
33
|
+
|
34
|
+
# =>
|
35
|
+
# user system total real
|
36
|
+
# pluck 0.183333 0.011667 0.195000 ( 0.217569)
|
37
|
+
# select 0.701667 0.023333 0.725000 ( 0.766307)
|
38
|
+
# as_json 1.623333 0.041667 1.665000 ( 1.751188)
|
39
|
+
|
40
|
+
```
|
41
|
+
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it ( https://github.com/[my-github-username]/avgbm/fork )
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/avgbm.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'avgbm/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "avgbm"
|
8
|
+
spec.version = Avgbm::VERSION
|
9
|
+
spec.authors = ["Girish S"]
|
10
|
+
spec.email = ["girish.sonawane@gmail.com"]
|
11
|
+
spec.summary = %q{Adds avgbm method to Ruby Benchmark std lib.}
|
12
|
+
spec.description = %q{Adds Benchmark.avgbm method, that discards highest/lowest times and averages the remaining results.}
|
13
|
+
spec.homepage = "https://github.com/girishso/avgbm"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
data/lib/avgbm.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "avgbm/version"
|
2
|
+
require 'benchmark'
|
3
|
+
|
4
|
+
module Benchmark
|
5
|
+
|
6
|
+
def self.avgbm(iterations = 5, label_width = 0) # :yield: job
|
7
|
+
job = Job.new(label_width)
|
8
|
+
yield(job)
|
9
|
+
width = job.width + 1
|
10
|
+
|
11
|
+
hash = Hash.new { |hash, key| hash[key] = [] }
|
12
|
+
|
13
|
+
# benchmark
|
14
|
+
job.list.each { |label,item|
|
15
|
+
iterations.times do
|
16
|
+
hash[label.to_s] << Benchmark.measure(label, &item)
|
17
|
+
end
|
18
|
+
}
|
19
|
+
|
20
|
+
# minimum 5 iterations
|
21
|
+
iterations = iterations < 5 ? 5 : iterations
|
22
|
+
|
23
|
+
# discard the lowest and highest times
|
24
|
+
lower_bound = iterations / 5
|
25
|
+
upper_bound = iterations - lower_bound
|
26
|
+
|
27
|
+
hash.each_pair do |label, reports|
|
28
|
+
# discard the highest and lowest times
|
29
|
+
reports.sort! {|x, y| y.real <=> x.real}
|
30
|
+
hash[label] = reports[lower_bound...upper_bound]
|
31
|
+
|
32
|
+
# average the remaining
|
33
|
+
hash[label] = hash[label].inject{ |sum, el| sum + el } / hash[label].size
|
34
|
+
end
|
35
|
+
|
36
|
+
# print the results
|
37
|
+
print ' '*width + CAPTION
|
38
|
+
|
39
|
+
hash.each_pair do |label, reports|
|
40
|
+
print label.ljust(width)
|
41
|
+
print reports
|
42
|
+
end
|
43
|
+
|
44
|
+
hash
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: avgbm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Girish S
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Adds Benchmark.avgbm method, that discards highest/lowest times and averages
|
42
|
+
the remaining results.
|
43
|
+
email:
|
44
|
+
- girish.sonawane@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- avgbm.gemspec
|
55
|
+
- lib/avgbm.rb
|
56
|
+
- lib/avgbm/version.rb
|
57
|
+
homepage: https://github.com/girishso/avgbm
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.4.5
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Adds avgbm method to Ruby Benchmark std lib.
|
81
|
+
test_files: []
|