reddavis-benchmarker 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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 reddavis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ = Benchmarker
2
+
3
+ This is a very 0.0.1 attempt at building a benchmarking version of autotest.
4
+
5
+ While trying to make your code faster it can be a big pain and time waste having to keep switching to your benchmarks and then back again to your code.
6
+
7
+ It only works on OSX at the moment (because of fsevents).
8
+
9
+ == How To Use
10
+
11
+ Setup - your_file.rb
12
+ require 'rubygems'
13
+ require 'benchmarker'
14
+ require 'benchmark' # rubys benchmark
15
+
16
+ Benchmarker.go('path to your code') do
17
+ n = 2
18
+
19
+ Benchmark.bm do |x|
20
+ x.report { for i in 1..n; a = "1"; end }
21
+ x.report { n.times do ; a = "1"; end }
22
+ x.report { 1.upto(n) do ; a = "1"; end }
23
+ end
24
+
25
+ end
26
+
27
+ Start It
28
+ ruby your_file.rb
29
+
30
+ Watch It
31
+ Last Time: ["0.000015", "0.000010", "0.000010"]
32
+ Now : ["0.000017", "0.000010", "0.000010"]
33
+ Change : ["-13%", "0%", "0%"]
34
+
35
+ == Copyright
36
+
37
+ Copyright (c) 2009 reddavis. See LICENSE for details.
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "benchmarker"
8
+ gem.summary = %Q{Instant feedback benchmarking}
9
+ gem.description = %Q{Instant feedback benchmarking}
10
+ gem.email = "reddavis@gmail.com"
11
+ gem.homepage = "http://github.com/reddavis/benchmarker"
12
+ gem.authors = ["reddavis"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+
41
+
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ if File.exist?('VERSION')
48
+ version = File.read('VERSION')
49
+ else
50
+ version = ""
51
+ end
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "benchmarker #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{benchmarker}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["reddavis"]
12
+ s.date = %q{2009-08-18}
13
+ s.default_executable = %q{benchmarker}
14
+ s.description = %q{Instant feedback benchmarking}
15
+ s.email = %q{reddavis@gmail.com}
16
+ s.executables = ["benchmarker"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "benchmarker.gemspec",
29
+ "bin/benchmarker",
30
+ "example/application.rb",
31
+ "example/lib/tester.rb",
32
+ "lib/benchmarker.rb",
33
+ "lib/ext/kernel.rb",
34
+ "test/ext/test_kernel.rb",
35
+ "test/helper.rb",
36
+ "test/test_benchmarker.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/reddavis/benchmarker}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.5}
42
+ s.summary = %q{Instant feedback benchmarking}
43
+ s.test_files = [
44
+ "test/ext/test_kernel.rb",
45
+ "test/helper.rb",
46
+ "test/test_benchmarker.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ else
55
+ end
56
+ else
57
+ end
58
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(Dir.getwd)
3
+
4
+ require 'optparse'
5
+
6
+ options = OptionParser.new do |opts|
7
+ opts.on("-f", "--file [ARG]", "Path to file") do |opt|
8
+ @file = opt
9
+ end
10
+ end
11
+
12
+ options.parse!(ARGV)
13
+
14
+ if File.exists?(@file)
15
+ system("ruby #{@file}")
16
+ else
17
+ raise "That's not a file!"
18
+ end
@@ -0,0 +1,13 @@
1
+ require 'benchmark'
2
+ require File.dirname(__FILE__) + '/../lib/benchmarker'
3
+
4
+ Benchmarker.go('lib') do
5
+ n = 2
6
+
7
+ Benchmark.bm do |x|
8
+ x.report { for i in 1..n; a = "1"; end }
9
+ x.report { n.times do ; a = "1"; end }
10
+ x.report { 1.upto(n) do ; a = "1"; end }
11
+ end
12
+
13
+ end
@@ -0,0 +1 @@
1
+ a = "Weeee!!"
@@ -0,0 +1,69 @@
1
+ $: << File.dirname(__FILE__)
2
+ require 'rubygems'
3
+ require 'fsevents'
4
+ require 'stringio'
5
+ require 'ext/kernel'
6
+
7
+ class Benchmarker
8
+ class << self
9
+
10
+ def go(path)
11
+ @path = path
12
+ check_path_exists
13
+ add_sigint_handler
14
+
15
+ stream = FSEvents::Stream.watch(path) do |events|
16
+ output = capture_stdout do
17
+ yield
18
+ end
19
+ times << grab_times(output.string).flatten
20
+ display_output
21
+ end
22
+ stream.run
23
+ end
24
+
25
+ def times
26
+ @times ||= []
27
+ end
28
+
29
+ def add_sigint_handler
30
+ trap 'INT' do
31
+ puts "Bye!"
32
+ raise Interrupt, nil # let the run loop catch it
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def display_output
39
+ output = ""
40
+ last_time = @times[-2]
41
+ now = @times[-1]
42
+ output << "Last Time: #{last_time.inspect}\n" if last_time
43
+ output << "Now : #{now.inspect}\n"
44
+ output << calculate_difference(last_time, now) if last_time
45
+ output << "-" * 50
46
+ puts output
47
+ end
48
+
49
+ def calculate_difference(last_time, now)
50
+ changes = []
51
+ last_time.each_with_index do |time, index|
52
+ a = "#{(((time.to_f - now[index].to_f) / time.to_f) * 100).to_i}%"
53
+ changes << a
54
+ end
55
+ "Change : #{changes.inspect}\n"
56
+ end
57
+
58
+ def grab_times(output)
59
+ output.scan(/(\d+\.?\d+)\)/)
60
+ end
61
+
62
+ def check_path_exists
63
+ unless File.directory?(@path)
64
+ raise "Error: Wheres your libs?"
65
+ end
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,10 @@
1
+ module Kernel
2
+ def capture_stdout
3
+ out = StringIO.new
4
+ $stdout = out
5
+ yield
6
+ return out
7
+ ensure
8
+ $stdout = STDOUT
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ require 'helper'
2
+
3
+ class TestKernel < Test::Unit::TestCase
4
+
5
+ should "a should contain hello" do
6
+ a = capture_stdout do
7
+ puts "hello"
8
+ end
9
+ assert_match(/hello/, a.string)
10
+ end
11
+
12
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'benchmarker'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,5 @@
1
+ require 'helper'
2
+
3
+ class TestBenchmarker < Test::Unit::TestCase
4
+ # Anyone want to give tips on testing this??
5
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reddavis-benchmarker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - reddavis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-18 00:00:00 -07:00
13
+ default_executable: benchmarker
14
+ dependencies: []
15
+
16
+ description: Instant feedback benchmarking
17
+ email: reddavis@gmail.com
18
+ executables:
19
+ - benchmarker
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - benchmarker.gemspec
33
+ - bin/benchmarker
34
+ - example/application.rb
35
+ - example/lib/tester.rb
36
+ - lib/benchmarker.rb
37
+ - lib/ext/kernel.rb
38
+ - test/ext/test_kernel.rb
39
+ - test/helper.rb
40
+ - test/test_benchmarker.rb
41
+ has_rdoc: false
42
+ homepage: http://github.com/reddavis/benchmarker
43
+ licenses:
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.3.5
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Instant feedback benchmarking
68
+ test_files:
69
+ - test/ext/test_kernel.rb
70
+ - test/helper.rb
71
+ - test/test_benchmarker.rb