benchmark_color 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +66 -0
- data/LICENSE.txt +20 -0
- data/README.md +84 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/benchmark_color.gemspec +66 -0
- data/lib/benchmark_color.rb +113 -0
- data/test/helper.rb +36 -0
- data/test/test_benchmark_color.rb +63 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6376a133153b1187337c43619b703f952df86a9e
|
4
|
+
data.tar.gz: e8a17b237dddf672622e413569532e6c5aa5691b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f76a87fe18fb4d11a7eddc30c50ab078a9439e51fbe344d2add8390bf5b0876047554029fbf667df19ad2ad0e39c45749f5adf0fdea93994e5e9cc29d13b8f5
|
7
|
+
data.tar.gz: a213ed1eb9aed1826f0e7ce270cdcd8b6c60a180bb1cb7f3e062010bec01c3321ff53ddd74dab6f40b18093110591b6978e3b1fc99dbba2f40f96d7fb685e5aa
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
#
|
4
|
+
gem "colorize"
|
5
|
+
|
6
|
+
# Example:
|
7
|
+
# gem "activesupport", ">= 2.3.5"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "minitest", ">= 0"
|
13
|
+
gem "rdoc", "~> 3.12"
|
14
|
+
gem "bundler", "~> 1.0"
|
15
|
+
gem "jeweler", "~> 2.0.1"
|
16
|
+
gem "simplecov", ">= 0"
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.5)
|
5
|
+
builder (3.2.2)
|
6
|
+
colorize (0.6.0)
|
7
|
+
descendants_tracker (0.0.3)
|
8
|
+
docile (1.1.3)
|
9
|
+
faraday (0.9.0)
|
10
|
+
multipart-post (>= 1.2, < 3)
|
11
|
+
git (1.2.6)
|
12
|
+
github_api (0.11.2)
|
13
|
+
addressable (~> 2.3)
|
14
|
+
descendants_tracker (~> 0.0.1)
|
15
|
+
faraday (~> 0.8, < 0.10)
|
16
|
+
hashie (>= 1.2)
|
17
|
+
multi_json (>= 1.7.5, < 2.0)
|
18
|
+
nokogiri (~> 1.6.0)
|
19
|
+
oauth2
|
20
|
+
hashie (2.0.5)
|
21
|
+
highline (1.6.20)
|
22
|
+
jeweler (2.0.1)
|
23
|
+
builder
|
24
|
+
bundler (>= 1.0)
|
25
|
+
git (>= 1.2.5)
|
26
|
+
github_api
|
27
|
+
highline (>= 1.6.15)
|
28
|
+
nokogiri (>= 1.5.10)
|
29
|
+
rake
|
30
|
+
rdoc
|
31
|
+
json (1.8.1)
|
32
|
+
jwt (0.1.11)
|
33
|
+
multi_json (>= 1.5)
|
34
|
+
mini_portile (0.5.2)
|
35
|
+
minitest (5.2.2)
|
36
|
+
multi_json (1.9.2)
|
37
|
+
multi_xml (0.5.5)
|
38
|
+
multipart-post (2.0.0)
|
39
|
+
nokogiri (1.6.1)
|
40
|
+
mini_portile (~> 0.5.0)
|
41
|
+
oauth2 (0.9.3)
|
42
|
+
faraday (>= 0.8, < 0.10)
|
43
|
+
jwt (~> 0.1.8)
|
44
|
+
multi_json (~> 1.3)
|
45
|
+
multi_xml (~> 0.5)
|
46
|
+
rack (~> 1.2)
|
47
|
+
rack (1.5.2)
|
48
|
+
rake (10.2.2)
|
49
|
+
rdoc (3.12.2)
|
50
|
+
json (~> 1.4)
|
51
|
+
simplecov (0.8.2)
|
52
|
+
docile (~> 1.1.0)
|
53
|
+
multi_json
|
54
|
+
simplecov-html (~> 0.8.0)
|
55
|
+
simplecov-html (0.8.0)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
ruby
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
bundler (~> 1.0)
|
62
|
+
colorize
|
63
|
+
jeweler (~> 2.0.1)
|
64
|
+
minitest
|
65
|
+
rdoc (~> 3.12)
|
66
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Matthew Sullivan
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
## benchmark_color
|
2
|
+
|
3
|
+
This is a simple realtime benchmark tool in color!
|
4
|
+
|
5
|
+
####Installation
|
6
|
+
|
7
|
+
gem install 'benchmark_color'
|
8
|
+
|
9
|
+
#### Getting Started
|
10
|
+
In the top of your file or in irb.
|
11
|
+
|
12
|
+
require 'benchmark_color'
|
13
|
+
|
14
|
+
Create a new Benchmark object
|
15
|
+
|
16
|
+
b = Benchmark.new
|
17
|
+
|
18
|
+
Measure a block of code
|
19
|
+
|
20
|
+
n = 10000
|
21
|
+
b.measure("some-label:") {n.times.do ; x = 1; end}
|
22
|
+
|
23
|
+
Use the Compare method to recieve an output
|
24
|
+
|
25
|
+
b.compare
|
26
|
+
|
27
|
+
The whole thing together will look something like this.
|
28
|
+
|
29
|
+
b = Benchmark.new
|
30
|
+
b.measure("some-label:") { YOUR BLOCK OF CODE}
|
31
|
+
b.compare
|
32
|
+
|
33
|
+
You can measure as many blocks of code to be compared to one another as the same Benchmark object. For example.
|
34
|
+
|
35
|
+
....
|
36
|
+
b = Benchmark.new
|
37
|
+
b.measure("some-label":) {YOUR BLOCK OF CODE}
|
38
|
+
b.measure("some-label:") {YOUR BLOCK OF CODE}
|
39
|
+
b.compare
|
40
|
+
|
41
|
+
####Customizing colors
|
42
|
+
When you create a Benchmark object just include the colors you prefer.
|
43
|
+
benchmark_color uses the awesome 'colorize ' gem so the colors need to be a symbol.
|
44
|
+
By default the fastest block of code will be green and the slowest red.
|
45
|
+
Therfore winner: :green, loser: :red.
|
46
|
+
|
47
|
+
b = Benchmark.new winner: :cyan, loser: :magenta, option: :yellow
|
48
|
+
|
49
|
+
The option: color argument is for the blocks of code that were neither fastest or slowest.
|
50
|
+
|
51
|
+
Colorize is an extension to the String class. To see a list of all the colors
|
52
|
+
just use:
|
53
|
+
|
54
|
+
String.colors
|
55
|
+
|
56
|
+
####Screen Shots
|
57
|
+
File Setup
|
58
|
+
|
59
|
+
![file](http://i.imgur.com/MdQPkHR.png)
|
60
|
+
|
61
|
+
Output
|
62
|
+
|
63
|
+
![output](http://i.imgur.com/Tr2oib3.png)
|
64
|
+
|
65
|
+
####Future Features
|
66
|
+
+ Process:Tms integration
|
67
|
+
+ More customizations
|
68
|
+
|
69
|
+
|
70
|
+
####Contributing to benchmark_color
|
71
|
+
|
72
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
73
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
74
|
+
* Fork the project.
|
75
|
+
* Start a feature/bugfix branch.
|
76
|
+
* Commit and push until you are happy with your contribution.
|
77
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
78
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
79
|
+
|
80
|
+
###### Copyright
|
81
|
+
|
82
|
+
Copyright (c) 2014 Matthew Sullivan. See LICENSE.txt for
|
83
|
+
further details.
|
84
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "benchmark_color"
|
18
|
+
gem.homepage = "http://github.com/hayduke19us/benchmark_color"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A simple realtime benchmark for ruby --> in Color!}
|
21
|
+
gem.description = %Q{Customize the output with your own colors.}
|
22
|
+
gem.email = "hayduke19us@gmail.com"
|
23
|
+
gem.authors = ["Matthew Sullivan"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Code coverage detail"
|
36
|
+
task :simplecov do
|
37
|
+
ENV['COVERAGE'] = "true"
|
38
|
+
Rake::Task['test'].execute
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rdoc/task'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "benchmark_color #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: benchmark_color 0.1.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "benchmark_color"
|
9
|
+
s.version = "0.1.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Matthew Sullivan"]
|
14
|
+
s.date = "2014-04-22"
|
15
|
+
s.description = "Customize the output with your own colors."
|
16
|
+
s.email = "hayduke19us@gmail.com"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"benchmark_color.gemspec",
|
30
|
+
"lib/benchmark_color.rb",
|
31
|
+
"test/helper.rb",
|
32
|
+
"test/test_benchmark_color.rb"
|
33
|
+
]
|
34
|
+
s.homepage = "http://github.com/hayduke19us/benchmark_color"
|
35
|
+
s.licenses = ["MIT"]
|
36
|
+
s.rubygems_version = "2.2.2"
|
37
|
+
s.summary = "A simple realtime benchmark for ruby --> in Color!"
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
s.specification_version = 4
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_runtime_dependency(%q<colorize>, [">= 0"])
|
44
|
+
s.add_development_dependency(%q<minitest>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
46
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
47
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
48
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<colorize>, [">= 0"])
|
51
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
52
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
53
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
54
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
55
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<colorize>, [">= 0"])
|
59
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
60
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
61
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
62
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
63
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require "colorize"
|
2
|
+
|
3
|
+
module Abacus
|
4
|
+
|
5
|
+
def self.block_time
|
6
|
+
measure {yield}
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.measure
|
10
|
+
#to add Process::Tms object in future
|
11
|
+
start_process, before = Process.times, Time.now
|
12
|
+
yield
|
13
|
+
end_process, after = Process.times, Time.now
|
14
|
+
((after - before) * 1000)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module Report
|
19
|
+
$stdout.sync = true
|
20
|
+
|
21
|
+
def self.output block_hash, winner, loser, option
|
22
|
+
unless block_hash.count == 1
|
23
|
+
block_array = block_hash.sort_by {|k, v| v}
|
24
|
+
first = block_array.shift
|
25
|
+
last = block_array.pop
|
26
|
+
Report.format first, last, block_array, winner, loser, option
|
27
|
+
else
|
28
|
+
block_hash = block_hash.flatten.join(' ')
|
29
|
+
Report.seperator
|
30
|
+
puts
|
31
|
+
puts "#{Report.arrow}" "#{block_hash.colorize(color: winner)}"
|
32
|
+
puts
|
33
|
+
Report.seperator
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.format first, last, block_array, winner, loser, option
|
39
|
+
puts Report.seperator
|
40
|
+
puts "#{Report.arrow}" "#{ first.join(' ').colorize(color: winner)}"
|
41
|
+
block_array.each do |block|
|
42
|
+
puts "#{Report.small_arrow}" "#{block.join(' ').colorize(color: option)}"
|
43
|
+
end
|
44
|
+
puts "#{Report.arrow}" "#{ last.join(' ').colorize(color: loser)}"
|
45
|
+
puts
|
46
|
+
puts Report.seperator
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.arrow
|
50
|
+
" -----------------------> ".colorize(color: :light_blue)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.small_arrow
|
54
|
+
" ----> ".colorize(color: :light_blue)
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.seperator
|
58
|
+
puts "=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
class Benchmark
|
64
|
+
|
65
|
+
attr_reader :block_hash
|
66
|
+
attr_accessor :winner, :loser, :option
|
67
|
+
|
68
|
+
include Abacus
|
69
|
+
include Report
|
70
|
+
|
71
|
+
def initialize args={}
|
72
|
+
@winner = args.fetch(:winner, :green)
|
73
|
+
@loser = args.fetch(:loser, :red)
|
74
|
+
@option = args.fetch(:option, :light_blue)
|
75
|
+
@block_hash ||= {}
|
76
|
+
end
|
77
|
+
|
78
|
+
def measure label = ""
|
79
|
+
if block_given?
|
80
|
+
block = Abacus.block_time {yield}
|
81
|
+
@block_hash[label] = block
|
82
|
+
true
|
83
|
+
else
|
84
|
+
puts instructions
|
85
|
+
false
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def compare
|
90
|
+
Report.output @block_hash, winner, loser, option
|
91
|
+
end
|
92
|
+
|
93
|
+
def instructions
|
94
|
+
%{You must supply a block of code like this:
|
95
|
+
|
96
|
+
b = Benchmark.new
|
97
|
+
b.measure("some-label:") { n.times do; x = 1 + 3; end}
|
98
|
+
b.compare #to get your results
|
99
|
+
|
100
|
+
Or this:
|
101
|
+
|
102
|
+
n = 1000
|
103
|
+
b = Benchmark.new
|
104
|
+
b.measure("some-label:") do
|
105
|
+
n.times do
|
106
|
+
x = 1 + 3
|
107
|
+
end
|
108
|
+
end
|
109
|
+
b.compare #to get your results}
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_adapter 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
require 'rubygems'
|
18
|
+
require 'bundler'
|
19
|
+
begin
|
20
|
+
Bundler.setup(:default, :development)
|
21
|
+
rescue Bundler::BundlerError => e
|
22
|
+
$stderr.puts e.message
|
23
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
24
|
+
exit e.status_code
|
25
|
+
end
|
26
|
+
require 'minitest/autorun'
|
27
|
+
require 'minitest/pride'
|
28
|
+
|
29
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
30
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
31
|
+
require 'benchmark_color'
|
32
|
+
|
33
|
+
class MiniTest::Test
|
34
|
+
end
|
35
|
+
|
36
|
+
MiniTest.autorun
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestBenchmark < MiniTest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@bench = Benchmark.new
|
7
|
+
@color = Benchmark.new(winner: :blue, loser: :yellow)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_if_no_winner_color_is_present_the_default_is_green
|
11
|
+
assert_equal :green, @bench.winner
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_if_no_loser_color_is_present_the_default_is_red
|
15
|
+
assert_equal :red, @bench.loser
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_if_no_option_is_set_the_default_is_light_blue
|
19
|
+
assert_equal :light_blue, @bench.option
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_a_user_sets_a_color_that_color_is_present
|
23
|
+
assert_equal :blue, @color.winner
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_the_colors_can_be_set_after_object_is_written
|
27
|
+
@color.winner = :yellow
|
28
|
+
assert_equal :yellow, @color.winner
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_if_a_label_is_the_same_it_wont_repeat_the_test
|
32
|
+
@bench.measure {}
|
33
|
+
@bench.measure {}
|
34
|
+
assert_equal 1, @bench.block_hash.count
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_if_the_labels_are_different_block_will_be_added_to_block_hash
|
38
|
+
@bench.measure("something") {}
|
39
|
+
@bench.measure {}
|
40
|
+
assert_equal 2, @bench.block_hash.count
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_the_colors_can_be_changed_half_way_thru_the_benchmark_process
|
44
|
+
n = 5000
|
45
|
+
x = 1000
|
46
|
+
@bench.measure("something") {n.times do; a = 1; end;}
|
47
|
+
@bench.measure("else") {x.times do; a = 1; end;}
|
48
|
+
@bench.winner = :cyan
|
49
|
+
@bench.loser = :light_black
|
50
|
+
@bench.measure("new_something") {n.times do; a = 1 + 4; end;}
|
51
|
+
@bench.measure("new_else") {x.times do; a = 1 + 4; end;}
|
52
|
+
@bench.compare
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_if_block_is_given_return_true
|
56
|
+
assert_equal true, @bench.measure {}
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_if_no_block_is_given_user_gets_instructions
|
60
|
+
assert_equal false, @bench.measure
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: benchmark_color
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Sullivan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
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: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.0.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.0.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Customize the output with your own colors.
|
98
|
+
email: hayduke19us@gmail.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files:
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.md
|
104
|
+
files:
|
105
|
+
- .document
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- VERSION
|
112
|
+
- benchmark_color.gemspec
|
113
|
+
- lib/benchmark_color.rb
|
114
|
+
- test/helper.rb
|
115
|
+
- test/test_benchmark_color.rb
|
116
|
+
homepage: http://github.com/hayduke19us/benchmark_color
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.2.2
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: A simple realtime benchmark for ruby --> in Color!
|
140
|
+
test_files: []
|