penchmark 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ab9aa6003b5bcac9a7544ce719710a8bd1f82a6
4
+ data.tar.gz: 17732d8e0a707193bf56e528e2277780dc149c48
5
+ SHA512:
6
+ metadata.gz: dda366e3811e079c701d8ff85c39741b876033e71b3dfd5e2a5a43ea8747de33e1881e9bfea00b1acb340b1fc8e01dbc3515f336fd956ac85371cf9be929089e
7
+ data.tar.gz: 6dc8da3888dd67f567ddcb9f2bbcc723f2b40d3ba0cc92cc1a8c3edd5f4f45a52daad5ca371ffc2573b3132325e9932724306475825ff58d7af9f51c855f19fe
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in penchmark.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 essjaybee
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,76 @@
1
+ # Penchmark
2
+
3
+ Colorized output for Ruby's Benchmark.
4
+ First version for safekeeping, refactoring to be done to reduce how much it is dependant on current version of benchmark
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'penchmark'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install penchmark # SORRY! Not available yet.
19
+
20
+ ## Usage
21
+
22
+ Use Benchmark as normal. If you want pretty colored output use .penchmark or .pbm instead.
23
+
24
+
25
+ .report in the pbm/penchmark-block takes a min_value and max_value as an argument for colored OK/Warning output.
26
+
27
+
28
+ If the real time is outside of the min/max_value range the row will be colored accordingly.
29
+
30
+ Example:
31
+
32
+
33
+ ```ruby
34
+ require 'penchmark'
35
+
36
+ n = 10000
37
+ output = Benchmark.pbm do |x|
38
+ x.report("Test1", 0, 0.002) {
39
+ for i in 1..n;
40
+ a = "1";
41
+ end }
42
+
43
+ x.report("Test2", 0, 0.01) {
44
+ for i in 1..n;
45
+ a = "1";
46
+ end }
47
+
48
+ x.report("Test3", 0, 0.6) {
49
+ for i in 1..n*400;
50
+ a = "1";
51
+ end }
52
+
53
+ x.report("Test4", 0, 0.7) {
54
+ for i in 1..n;
55
+ a = "1";
56
+ end }
57
+
58
+ x.report("Test5", 0, 0.2) {
59
+ for i in 1..n;
60
+ a = "1";
61
+ end }
62
+
63
+ x.report("Test6", 0, 0.9 ) {
64
+ for i in 1..n;
65
+ a = "1";
66
+ end }
67
+ end
68
+ ```
69
+
70
+ ## Contributing
71
+
72
+ 1. Fork it
73
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
74
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
75
+ 4. Push to the branch (`git push origin my-new-feature`)
76
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,51 @@
1
+ require 'benchmark'
2
+
3
+ module Benchmark
4
+ class ColoredReport
5
+ def initialize(width = 0, format = nil)
6
+ @width, @format, @list = width, format, []
7
+ end
8
+
9
+ def item(label = "", min_value = 0.0, max_value = 1.1, *format, &blk) # :yield:
10
+ @list << res = Benchmark.measure(label, &blk)
11
+ real_value = res.real
12
+
13
+ if real_value > min_value and real_value < max_value
14
+ print label.to_s.ljust(@width).green
15
+ print res.format(@format, *format).green
16
+ else
17
+ print label.to_s.ljust(@width).red
18
+ print res.format(@format, *format).red
19
+ end
20
+ res
21
+ end
22
+
23
+ alias report item
24
+
25
+ attr_reader :list
26
+ end
27
+
28
+ def self.penchmark(caption = '', label_width = nil, format = nil, *labels)
29
+ label_width ||= 0
30
+ label_width += 1
31
+ format ||= FORMAT
32
+ print "#{' '*label_width + caption}".blue unless caption.empty?
33
+ report = ColoredReport.new(label_width, format)
34
+ results = yield(report)
35
+ print "#{'-'*label_width}\n".yellow
36
+ Array === results and results.grep(Tms).each { |t|
37
+ print((labels.shift || t.label || "").ljust(label_width).yellow, t.format(format.yellow))
38
+ }
39
+ report.list
40
+ end
41
+
42
+
43
+ def self.pbm(label_width = 0, &block)
44
+ #puts 'test'
45
+ label_width ||= 0
46
+ label_width += 1
47
+ print "#{' '*label_width + CAPTION}".pink unless CAPTION.empty?
48
+ report = ColoredReport.new(3, nil)
49
+ yield(report) if block_given?
50
+ end
51
+ end
@@ -0,0 +1,27 @@
1
+ module Penchmark
2
+ String.class_eval do
3
+ def colorize(color_code)
4
+ "\e[#{color_code}m#{self}\e[0m"
5
+ end
6
+
7
+ def red
8
+ colorize(31)
9
+ end
10
+
11
+ def green
12
+ colorize(32)
13
+ end
14
+
15
+ def yellow
16
+ colorize(33)
17
+ end
18
+
19
+ def pink
20
+ colorize(35)
21
+ end
22
+
23
+ def blue
24
+ colorize(34)
25
+ end
26
+ end
27
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ module Penchmark
2
+ VERSION = "0.0.1"
3
+ end
data/lib/penchmark.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'penchmark/version'
2
+ require 'penchmark/test'
3
+ require 'penchmark/string'
4
+ require 'penchmark/benchmark'
5
+
6
+
7
+
8
+
9
+
10
+
data/penchmark.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'penchmark/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'penchmark'
8
+ spec.version = Penchmark::VERSION
9
+ spec.authors = ["essjaybee"]
10
+ spec.email = ["essjaybee@gmail.com"]
11
+ spec.description = %q{Colorized output of Benchmark}
12
+ spec.summary = %q{Colorized output of Benchmark}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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
+
22
+
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec", "~> 2.6"
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: penchmark
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - essjaybee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-27 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
55
+ description: Colorized output of Benchmark
56
+ email:
57
+ - essjaybee@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/penchmark.rb
68
+ - lib/penchmark/benchmark.rb
69
+ - lib/penchmark/string.rb
70
+ - lib/penchmark/test.rb
71
+ - lib/penchmark/version.rb
72
+ - penchmark.gemspec
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.0.rc.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Colorized output of Benchmark
97
+ test_files: []