rgauge 1.0.4

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.
@@ -0,0 +1,29 @@
1
+
2
+ === 1.0.4 / 2009-03-19
3
+
4
+ * Added warmup support
5
+ * Added #swap_caption
6
+ * Misc refactoring
7
+ * Removed #assign_report_performance
8
+
9
+ === 1.0.3 / 2009-01-30
10
+
11
+ * Added :scale option, alias of :duration_scale
12
+ * Added :format option, alias of :duration_format
13
+ * Updated length of report, made it larger to support larger labels
14
+
15
+ === 1.0.1 / 2009-01-16
16
+
17
+ * Changed spinner to include the caption like: / benchmarking @caption
18
+
19
+ === 1.0.0 / 2009-01-16
20
+
21
+ * Added sexy ANSI progress indication spinner
22
+
23
+ === 0.0.2 / 2009-01-16
24
+
25
+ * Added progress indication
26
+
27
+ === 0.0.1 / 2009-01-15
28
+
29
+ * Initial release
@@ -0,0 +1,19 @@
1
+ examples/simple.rb
2
+ History.rdoc
3
+ lib/rgauge/formatters/terminal.rb
4
+ lib/rgauge/formatters.rb
5
+ lib/rgauge/import.rb
6
+ lib/rgauge/runner.rb
7
+ lib/rgauge/version.rb
8
+ lib/rgauge.rb
9
+ Manifest
10
+ Rakefile
11
+ README.rdoc
12
+ rgauge.gemspec
13
+ spec/functional/rguage_spec.rb
14
+ spec/spec_helper.rb
15
+ tasks/benchmark.rake
16
+ tasks/docs.rake
17
+ tasks/gemspec.rake
18
+ tasks/spec.rake
19
+ Todo.rdoc
@@ -0,0 +1,57 @@
1
+
2
+ = RGauge
3
+
4
+ Ultra slick benchmarking DSL, sexiest of them all.
5
+
6
+ == Features:
7
+
8
+ * Simple
9
+ * Nestable
10
+ * Sorts performance results ascending (fastest first, easy on the brain)
11
+ * Pretty (ansi escape sequences sexify things, and progress indication)
12
+ * Formatters (more to come)
13
+
14
+ == Example:
15
+
16
+ require 'rubygems'
17
+ require 'rgauge'
18
+
19
+ benchmark 'Inflection', :times => 100_000 do
20
+ report('camel_case') { 'underscore_string'.camel_case }
21
+ report('snake_case') { 'CamelCaseString'.snake_case }
22
+ report('pluralize') { 'lots of goose'.pluralize }
23
+ end
24
+
25
+ == Output:
26
+
27
+ Inflection 100,000 times
28
+ ---------------------------------------
29
+ pluralize 0.408 |
30
+ camel_case 1.078 |
31
+ snake_case 1.197 |
32
+
33
+ == License:
34
+
35
+ (The MIT License)
36
+
37
+ Copyright (c) 2008 TJ Holowaychuk <tj@vision-media.ca>
38
+
39
+ Permission is hereby granted, free of charge, to any person obtaining
40
+ a copy of this software and associated documentation files (the
41
+ 'Software'), to deal in the Software without restriction, including
42
+ without limitation the rights to use, copy, modify, merge, publish,
43
+ distribute, sublicense, an d/or sell copies of the Software, and to
44
+ permit persons to whom the Software is furnished to do so, subject to
45
+ the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be
48
+ included in all copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
51
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
52
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
53
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
54
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
55
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
56
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
57
+ LINGS IN THE SOFTWARE.
@@ -0,0 +1,14 @@
1
+
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'echoe'
5
+ require './lib/rgauge.rb'
6
+
7
+ Echoe.new("rgauge", RGauge::VERSION) do |p|
8
+ p.author = "TJ Holowaychuk"
9
+ p.email = "tj@vision-media.ca"
10
+ p.summary = "Ultra slick benchmarking DSL"
11
+ p.url = "http://github.com/visionmedia/rgauge"
12
+ end
13
+
14
+ Dir['tasks/**/*.rake'].sort.each { |lib| load lib }
@@ -0,0 +1,15 @@
1
+
2
+ == Major:
3
+
4
+ * Allow array of 'times' and re-benchmark each of those times
5
+ * Allow overriding of options via #report
6
+ * Comparison percentages (best being 100%, 1/3 slower 150% etc)
7
+ * More formatters like charts
8
+
9
+ == Minor:
10
+
11
+ * Nothing
12
+
13
+ == Brainstorming:
14
+
15
+ * Nothing
@@ -0,0 +1,26 @@
1
+
2
+ $:.unshift File.dirname(__FILE__) + '/../lib'
3
+
4
+ require 'rgauge'
5
+ require 'benchmark'
6
+ require 'rubygems'
7
+ require 'extlib'
8
+
9
+ # RGauge
10
+
11
+ benchmark 'Inflection', :times => 100_000, :scale => 4, :warmup => true do
12
+ report('camel_case') { 'underscore_string'.camel_case }
13
+ report('snake_case') { 'CamelCaseString'.snake_case }
14
+ report('pluralize') { 'lots of goose'.pluralize }
15
+ end
16
+
17
+ # Standard library benchmark.rb
18
+
19
+ puts
20
+ puts 'Standard library:'
21
+ n = 100_000
22
+ Benchmark.bm(15) do |x|
23
+ x.report("camel_case") { n.times do 'underscore_string'.camel_case end }
24
+ x.report("snake_case") { n.times do 'CamelCaseString'.snake_case end }
25
+ x.report("pluralize") { n.times do 'lots of goose'.pluralize end }
26
+ end
@@ -0,0 +1,29 @@
1
+ #--
2
+ # Copyright (c) 2008 TJ Holowaychuk
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ $:.unshift File.dirname(__FILE__)
25
+
26
+ require 'rgauge/version'
27
+ require 'rgauge/runner'
28
+ require 'rgauge/formatters'
29
+ require 'rgauge/import'
@@ -0,0 +1,6 @@
1
+
2
+ module RGauge
3
+ module Formatter
4
+ autoload :Terminal, 'rgauge/formatters/terminal'
5
+ end
6
+ end
@@ -0,0 +1,108 @@
1
+
2
+ module RGauge
3
+ module Formatter
4
+ class Terminal
5
+
6
+ ##
7
+ # Terminal benchmark formatter.
8
+
9
+ def initialize runner, reports
10
+ @runner, @reports = runner, reports
11
+ @scale = @runner.options.fetch :scale, 3
12
+ @format = @runner.options.fetch :format, "%0.#{@scale}f"
13
+ @reports = @reports.sort_by { |report| report[:duration] }
14
+ render
15
+ end
16
+
17
+ ##
18
+ # Render the benchmark reporting.
19
+
20
+ def render
21
+ s = '%-30s %s' % headings
22
+ s << seperator << render_rows
23
+ puts "#{indent(s)}\n\n"
24
+ end
25
+
26
+ ##
27
+ # Render a seperator.
28
+
29
+ def seperator
30
+ "\n#{ '-' * 49 }\n"
31
+ end
32
+
33
+ ##
34
+ # Render rows.
35
+
36
+ def render_rows
37
+ rows.map { |row| render_row row }.join "\n"
38
+ end
39
+
40
+ private
41
+
42
+ def render_row row
43
+ '%-34s %12s |' % row
44
+ end
45
+
46
+ ##
47
+ # Return formatted headings.
48
+
49
+ def headings
50
+ return @runner.caption, call_times
51
+ end
52
+
53
+ ##
54
+ # Return array of rows captured by the runner.
55
+
56
+ def rows
57
+ @reports.map do |report|
58
+ [report[:label], @format % report[:duration]]
59
+ end
60
+ end
61
+
62
+ ##
63
+ # Formatted number of times called label.
64
+
65
+ def call_times
66
+ return '' if @runner.n <= 1
67
+ '%20s times' % bold(sexify_int(@runner.n))
68
+ end
69
+
70
+ ##
71
+ # Wrap a string in red.
72
+
73
+ def red string
74
+ "\e[31m#{string}\e[0m"
75
+ end
76
+
77
+ ##
78
+ # Wrap a string in green.
79
+
80
+ def green string
81
+ "\e[32m#{string}\e[0m"
82
+ end
83
+
84
+ ##
85
+ # Wrap a string in bold.
86
+
87
+ def bold string
88
+ "\e[1m#{string}\e[0m"
89
+ end
90
+
91
+ ##
92
+ # Indent a +string+, x number of +spaces+.
93
+
94
+ def indent string, spaces = 2
95
+ string.to_s.gsub! /^/, (" " * spaces)
96
+ end
97
+
98
+ ##
99
+ # Sexify an +int+ by converting to a string and generating thousandths seperators.
100
+ # For example 1000000 becomes 1,000,000.
101
+
102
+ def sexify_int int
103
+ int.to_s.gsub /(\d)(?=(\d\d\d)+(?!\d))/, '\1,'
104
+ end
105
+
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module Kernel
3
+ def benchmark *args, &block
4
+ RGauge::Runner.new *args, &block
5
+ end
6
+ end
@@ -0,0 +1,130 @@
1
+
2
+ module RGauge
3
+ class Runner
4
+
5
+ attr_reader :options, :threads, :caption, :reports
6
+
7
+ ##
8
+ # Create a new runner with a given +caption+ and +options+.
9
+ #
10
+ # === Options:
11
+ #
12
+ # :times Number of times to call each procedure; Default 1
13
+ # :formatter Output formatter instantiated for reporting; Default RGauge::Formatter::Terminal
14
+ #
15
+ # Terminal formatter:
16
+ #
17
+ # :scale Decimals to the right of the duration. Default 3
18
+ # :format Format string used to output duration. Default '%0.#{duration_scale}f'
19
+ #
20
+
21
+ def initialize caption = '', options = {}, &block
22
+ @reports, @finished, @caption = [], false, "benchmarking #{caption}"
23
+ @options = { :times => 1, :formatter => Formatter::Terminal }.merge options
24
+ instance_eval &block
25
+ run!
26
+ end
27
+
28
+ ##
29
+ # Run the reports.
30
+
31
+ def run!
32
+ puts "\n"
33
+ display_progress
34
+ reports.each { |report| warmup report } if options[:warmup]
35
+ reports.each { |report| benchmark report }
36
+ finished!
37
+ options[:formatter].new self, @reports
38
+ end
39
+
40
+ ##
41
+ # Add a report with +label+ and +block+.
42
+
43
+ def report label = '', &block
44
+ @reports << { :label => label, :proc => block }
45
+ end
46
+
47
+ ##
48
+ # Number of times to perform the procedure call.
49
+
50
+ def n
51
+ options[:times].to_i
52
+ end
53
+
54
+ ##
55
+ # Wither or not the benchmarking is complete.
56
+
57
+ def finished?
58
+ @finished
59
+ end
60
+
61
+ ##
62
+ # Finish benchmarking.
63
+
64
+ def finished!
65
+ @finished = true
66
+ erase_line
67
+ end
68
+
69
+ ##
70
+ # Run the +report+ once to 'warm it up'.
71
+
72
+ def warmup report
73
+ swap_caption "warming up #{report[:label]}" do
74
+ report[:proc].call
75
+ end
76
+ end
77
+
78
+ ##
79
+ # Erase previous terminal line.
80
+
81
+ def erase_line
82
+ print "\r\e[K"
83
+ end
84
+
85
+ ##
86
+ # Set caption to +string+, setting back
87
+ # the original caption after block execution
88
+ # is complete.
89
+
90
+ def swap_caption string, &block
91
+ prev_caption, @caption = @caption, string
92
+ yield
93
+ @caption = prev_caption
94
+ end
95
+
96
+ ##
97
+ # Print a rgauge caption +string+.
98
+
99
+ def print_caption string, count = 0
100
+ s = '|', '/', '-', '\\'
101
+ print " \e[1m" + s[count % s.length] + "\e[0m #{string} "
102
+ $stdout.flush
103
+ erase_line
104
+ end
105
+
106
+ ##
107
+ # Benchmark a +report+.
108
+
109
+ def benchmark report
110
+ start = Time.now
111
+ for i in 1..n; report[:proc].call end
112
+ report[:duration] = (Time.now - start)
113
+ end
114
+
115
+ ##
116
+ # Display progress of benchmark.
117
+
118
+ def display_progress
119
+ Thread.new do
120
+ count = 0
121
+ until finished? do
122
+ print_caption caption, count
123
+ count += 1
124
+ sleep 0.05
125
+ end
126
+ end
127
+ end
128
+
129
+ end
130
+ end
@@ -0,0 +1,4 @@
1
+
2
+ module RGauge
3
+ VERSION = '1.0.4'
4
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rgauge}
5
+ s.version = "1.0.4"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["TJ Holowaychuk"]
9
+ s.date = %q{2009-03-19}
10
+ s.description = %q{Ultra slick benchmarking DSL}
11
+ s.email = %q{tj@vision-media.ca}
12
+ s.extra_rdoc_files = ["lib/rgauge/formatters/terminal.rb", "lib/rgauge/formatters.rb", "lib/rgauge/import.rb", "lib/rgauge/runner.rb", "lib/rgauge/version.rb", "lib/rgauge.rb", "README.rdoc", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
13
+ s.files = ["examples/simple.rb", "History.rdoc", "lib/rgauge/formatters/terminal.rb", "lib/rgauge/formatters.rb", "lib/rgauge/import.rb", "lib/rgauge/runner.rb", "lib/rgauge/version.rb", "lib/rgauge.rb", "Manifest", "Rakefile", "README.rdoc", "rgauge.gemspec", "spec/functional/rguage_spec.rb", "spec/spec_helper.rb", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake", "Todo.rdoc"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/visionmedia/rgauge}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rgauge", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{rgauge}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Ultra slick benchmarking DSL}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+
2
+ require 'rgauge'
3
+
@@ -0,0 +1,5 @@
1
+
2
+ desc 'Benchmark'
3
+ task :benchmark do
4
+ ruby 'examples/simple.rb'
5
+ end
@@ -0,0 +1,13 @@
1
+
2
+ namespace :docs do
3
+
4
+ desc 'Remove rdoc products'
5
+ task :remove => [:clobber_docs]
6
+
7
+ desc 'Build docs, and open in browser for viewing (specify BROWSER)'
8
+ task :open => [:docs] do
9
+ browser = ENV["BROWSER"] || "safari"
10
+ sh "open -a #{browser} doc/index.html"
11
+ end
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+
2
+ desc 'Build gemspec file'
3
+ task :gemspec => [:build_gemspec]
@@ -0,0 +1,25 @@
1
+
2
+ require 'spec/rake/spectask'
3
+
4
+ desc "Run all specifications"
5
+ Spec::Rake::SpecTask.new(:spec) do |t|
6
+ t.libs << "lib"
7
+ t.spec_opts = ["--color", "--require", "spec/spec_helper.rb"]
8
+ end
9
+
10
+ namespace :spec do
11
+
12
+ desc "Run all specifications verbosely"
13
+ Spec::Rake::SpecTask.new(:verbose) do |t|
14
+ t.libs << "lib"
15
+ t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
16
+ end
17
+
18
+ desc "Run specific specification verbosely (specify SPEC)"
19
+ Spec::Rake::SpecTask.new(:select) do |t|
20
+ t.libs << "lib"
21
+ t.spec_files = [ENV["SPEC"]]
22
+ t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
23
+ end
24
+
25
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rgauge
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ platform: ruby
6
+ authors:
7
+ - TJ Holowaychuk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-19 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Ultra slick benchmarking DSL
17
+ email: tj@vision-media.ca
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - lib/rgauge/formatters/terminal.rb
24
+ - lib/rgauge/formatters.rb
25
+ - lib/rgauge/import.rb
26
+ - lib/rgauge/runner.rb
27
+ - lib/rgauge/version.rb
28
+ - lib/rgauge.rb
29
+ - README.rdoc
30
+ - tasks/benchmark.rake
31
+ - tasks/docs.rake
32
+ - tasks/gemspec.rake
33
+ - tasks/spec.rake
34
+ files:
35
+ - examples/simple.rb
36
+ - History.rdoc
37
+ - lib/rgauge/formatters/terminal.rb
38
+ - lib/rgauge/formatters.rb
39
+ - lib/rgauge/import.rb
40
+ - lib/rgauge/runner.rb
41
+ - lib/rgauge/version.rb
42
+ - lib/rgauge.rb
43
+ - Manifest
44
+ - Rakefile
45
+ - README.rdoc
46
+ - rgauge.gemspec
47
+ - spec/functional/rguage_spec.rb
48
+ - spec/spec_helper.rb
49
+ - tasks/benchmark.rake
50
+ - tasks/docs.rake
51
+ - tasks/gemspec.rake
52
+ - tasks/spec.rake
53
+ - Todo.rdoc
54
+ has_rdoc: true
55
+ homepage: http://github.com/visionmedia/rgauge
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --line-numbers
61
+ - --inline-source
62
+ - --title
63
+ - Rgauge
64
+ - --main
65
+ - README.rdoc
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "1.2"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project: rgauge
83
+ rubygems_version: 1.3.5
84
+ signing_key:
85
+ specification_version: 2
86
+ summary: Ultra slick benchmarking DSL
87
+ test_files: []
88
+