tach 0.0.0

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,39 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # jeweler generated
12
+ pkg
13
+
14
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
15
+ #
16
+ # * Create a file at ~/.gitignore
17
+ # * Include files you want ignored
18
+ # * Run: git config --global core.excludesfile ~/.gitignore
19
+ #
20
+ # After doing this, these files will be ignored in all your git projects,
21
+ # saving you from having to 'pollute' every project you touch with them
22
+ #
23
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
24
+ #
25
+ # For MacOS:
26
+ #
27
+ #.DS_Store
28
+ #
29
+ # For TextMate
30
+ #*.tmproj
31
+ #tmtags
32
+ #
33
+ # For emacs:
34
+ #*~
35
+ #\#*
36
+ #.\#*
37
+ #
38
+ # For vim:
39
+ #*.swp
data/README.rdoc ADDED
@@ -0,0 +1,56 @@
1
+ = tach
2
+
3
+ Shotgun benchmarking with noticeable progress and pretty results.
4
+
5
+ == Writing Benchmarks
6
+
7
+ == Note on Patches/Pull Requests
8
+
9
+ Benchmarks are pretty easy, I'll explain a simple example
10
+
11
+ Tach.meter(4) do
12
+
13
+ tach('first') do
14
+ sleep(rand)
15
+ end
16
+
17
+ tach('second') do
18
+ sleep(rand)
19
+ end
20
+
21
+ end
22
+
23
+ The optional argument to meter tells it how many times to run each tach (it defaults to 1).
24
+ Each tach should have a name, so you can recognize them in the results.
25
+ Then inside the tach block you should specify the code you care about comparing.
26
+ The output will show you the progress through each tach and average/total real times for each one when they finish.
27
+ Each tach will be run all its repetitions in its own thread, with a new thread for each tach.
28
+
29
+ BUT BUT, why does my progressbar take longer than the total time listed in the table?
30
+ Well, displaying the progressbar is kinda slow, but that time doesn't count against the total for the tach.
31
+ I'll be using tach to help me make it go faster, and then I'll (hopefully remember to) remove this notice!
32
+
33
+ == Copyright
34
+
35
+ (The MIT License)
36
+
37
+ Copyright (c) 2010 {geemus (Wesley Beary)}[http://github.com/geemus]
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, and/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
53
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
54
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
55
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
56
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "tach"
8
+ gem.summary = %Q{Shotgun benchmarking}
9
+ gem.description = %Q{Shotgun benchmarking with noticeable progress and pretty results.}
10
+ gem.email = "wbeary@engineyard.com"
11
+ gem.homepage = "http://github.com/geemus/tach"
12
+ gem.authors = ["geemus (Wesley Beary)"]
13
+ gem.add_dependency "formatador", ">= 0.0.12"
14
+ gem.add_development_dependency "shindo", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'shindo/rake'
22
+ Shindo::Rake.new
23
+
24
+ begin
25
+ require 'rcov/rcovtask'
26
+ Rcov::RcovTask.new do |tests|
27
+ tests.libs << 'tests'
28
+ tests.pattern = 'tests/**/*_tests.rb'
29
+ tests.verbose = true
30
+ end
31
+ rescue LoadError
32
+ task :rcov do
33
+ abort "RCov is not available. In order to run rcov, you must: gem install spicycode-rcov"
34
+ end
35
+ end
36
+
37
+ task :tests => :check_dependencies
38
+
39
+ task :default => :tests
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "tach #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/lib/tach.rb ADDED
@@ -0,0 +1,88 @@
1
+ require 'rubygems'
2
+ require 'annals'
3
+ require 'formatador'
4
+
5
+ module Tach
6
+
7
+ def self.meter(times = 1, &block)
8
+ Tach::Meter.new(times, &block)
9
+ end
10
+
11
+ class Meter
12
+
13
+ def initialize(times = 1, &block)
14
+ @benchmarks = []
15
+ @results = {}
16
+ @times = times
17
+
18
+ instance_eval(&block)
19
+
20
+ Formatador.display_line
21
+ longest = @benchmarks.map {|benchmark| benchmark[0]}.map {|name| name.length}.max
22
+ for name, block in @benchmarks
23
+ @results[name] = run_in_thread("#{name}#{' ' * (longest - name.length)}", @times, &block)
24
+ end
25
+
26
+ data = []
27
+ for name, block in @benchmarks
28
+ value = @results[name]
29
+ total = value.inject(0) {|sum,item| sum + item}
30
+ data << { :average => format("%8.6f", (total / value.length)), :tach => name, :total => format("%8.6f", total) }
31
+ end
32
+
33
+ Formatador.display_table(data, [:tach, :average, :total])
34
+ Formatador.display_line
35
+ end
36
+
37
+ def tach(name, &block)
38
+ @benchmarks << [name, block]
39
+ end
40
+
41
+ private
42
+
43
+ def run_in_thread(name, count, &benchmark)
44
+ if count.to_s.length > 3
45
+ divisor = 1
46
+ (count.to_s.length - 3).times do
47
+ divisor *= 10
48
+ end
49
+ end
50
+ thread = Thread.new {
51
+ Thread.current[:results] ||= []
52
+ Thread.current[:started_at] = Time.now
53
+ Formatador.redisplay_progressbar(0, count, :label => name, :started_at => Thread.current[:started_at])
54
+ for index in 1..count
55
+ tach_start = Time.now
56
+ instance_eval(&benchmark)
57
+ Thread.current[:results] << Time.now.to_f - tach_start.to_f
58
+ if !divisor || index % divisor == 0
59
+ Formatador.redisplay_progressbar(index, count, :label => name, :started_at => Thread.current[:started_at])
60
+ end
61
+ end
62
+ Formatador.display_line
63
+ }
64
+ thread.join
65
+ thread[:results]
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+
72
+ if __FILE__ == $0
73
+
74
+ data = 'Content-Length: 100'
75
+ Tach.meter(1_000_000) do
76
+
77
+ tach('regex') do
78
+ header = data.match(/(.*):\s(.*)/)
79
+ [$1, $2]
80
+ end
81
+
82
+ tach('split') do
83
+ header = data.split(': ')
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/tests_helper')
2
+
3
+ Shindo.tests("Tach") do
4
+ test("fails") do
5
+ "hey buddy, you should probably rename this file and start specing for real"
6
+ false
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'tach'
4
+ require 'rubygems'
5
+ require 'shindo'
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tach
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ version: 0.0.0
10
+ platform: ruby
11
+ authors:
12
+ - geemus (Wesley Beary)
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-07 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: formatador
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 0
30
+ - 12
31
+ version: 0.0.12
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: shindo
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: Shotgun benchmarking with noticeable progress and pretty results.
47
+ email: wbeary@engineyard.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - README.rdoc
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - README.rdoc
58
+ - Rakefile
59
+ - VERSION
60
+ - lib/tach.rb
61
+ - tests/tach_tests.rb
62
+ - tests/tests_helper.rb
63
+ has_rdoc: true
64
+ homepage: http://github.com/geemus/tach
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --charset=UTF-8
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.6
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Shotgun benchmarking
93
+ test_files: []
94
+