benchm 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +138 -0
- data/benchm.gemspec +17 -0
- data/lib/benchm.rb +42 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ff702c49f1aa3014d2bb35650d49de0353038066
|
4
|
+
data.tar.gz: 091464a6c17e466670b8c46dfc888d3fdd7f8db3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6131ea3c244d6e9ceeab0bff562393b892c9659bb73b8ea8caa02e864f5c9136b4c54021f85451d2ece8211429cdc2b87558ce2f6e9e9cca58c91a1d51b63fbe
|
7
|
+
data.tar.gz: 2b461d8d1536166cadf2f534811b0be730a32a9bfbf40d5e4149705e64a03578108abb3ddfab6d8cf23e89f4a15f8ae2e85723350b8fa3c1e5d4fdaf2a26dc27
|
data/.gitignore
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Charles Chamberlain
|
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,138 @@
|
|
1
|
+
# Benchm
|
2
|
+
|
3
|
+
Benchm is the simplest way to time your programs.
|
4
|
+
|
5
|
+
• Labels
|
6
|
+
|
7
|
+
• Built-in Iteration
|
8
|
+
|
9
|
+
• Set Default Iteration
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
#### The simplest usage:
|
14
|
+
|
15
|
+
``` ruby
|
16
|
+
require 'benchm'
|
17
|
+
|
18
|
+
Benchm.ark do
|
19
|
+
sleep 0.5
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
Results in:
|
24
|
+
|
25
|
+
``` java
|
26
|
+
|
27
|
+
Total: 0.501139 seconds
|
28
|
+
Average: 0.501139 seconds
|
29
|
+
|
30
|
+
```
|
31
|
+
#### With Labels:
|
32
|
+
|
33
|
+
``` ruby
|
34
|
+
Benchm.ark 'sleeping' do
|
35
|
+
sleep 0.5
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Results in:
|
40
|
+
|
41
|
+
``` java
|
42
|
+
|
43
|
+
Sleeping Total: 0.501113 seconds
|
44
|
+
Sleeping Average: 0.501113 seconds
|
45
|
+
|
46
|
+
```
|
47
|
+
|
48
|
+
#### Built-in Iteration:
|
49
|
+
|
50
|
+
``` ruby
|
51
|
+
Benchm.ark 5 do
|
52
|
+
sleep 0.5
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
Results in:
|
57
|
+
|
58
|
+
``` java
|
59
|
+
|
60
|
+
Total: 2.504231 seconds
|
61
|
+
Average: 0.5008462 seconds
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
#### With adjustable default:
|
66
|
+
|
67
|
+
Benchm defaults to 1 repeat.
|
68
|
+
Change this easily:
|
69
|
+
|
70
|
+
``` ruby
|
71
|
+
Benchm.repeat = 5
|
72
|
+
|
73
|
+
Benchm.ark 'Test' do
|
74
|
+
sleep 0.5
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
Results in:
|
79
|
+
|
80
|
+
``` java
|
81
|
+
|
82
|
+
Test Total: 2.503483 seconds
|
83
|
+
Test Average: 0.5006966 seconds
|
84
|
+
|
85
|
+
```
|
86
|
+
|
87
|
+
|
88
|
+
#### Everything combined:
|
89
|
+
|
90
|
+
``` ruby
|
91
|
+
|
92
|
+
Benchm.repeat = 20
|
93
|
+
|
94
|
+
Benchm.ark 'first' do
|
95
|
+
sleep 0.5
|
96
|
+
end
|
97
|
+
|
98
|
+
Benchm.ark 'second' do
|
99
|
+
sleep 0.3
|
100
|
+
end
|
101
|
+
|
102
|
+
```
|
103
|
+
|
104
|
+
Results in:
|
105
|
+
|
106
|
+
``` java
|
107
|
+
|
108
|
+
First Total: 10.011907 seconds
|
109
|
+
First Average: 0.50059535 seconds
|
110
|
+
|
111
|
+
|
112
|
+
Second Total: 6.010031 seconds
|
113
|
+
Second Average: 0.30050155 seconds
|
114
|
+
|
115
|
+
```
|
116
|
+
|
117
|
+
|
118
|
+
## Installation
|
119
|
+
|
120
|
+
Add this line to your application's Gemfile:
|
121
|
+
``` ruby
|
122
|
+
gem 'benchm'
|
123
|
+
```
|
124
|
+
And then execute:
|
125
|
+
|
126
|
+
$ bundle
|
127
|
+
|
128
|
+
Or install it yourself as:
|
129
|
+
|
130
|
+
$ gem install benchm
|
131
|
+
|
132
|
+
## Contributing
|
133
|
+
|
134
|
+
1. Fork it
|
135
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
136
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
137
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
138
|
+
5. Create new Pull Request
|
data/benchm.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "benchm"
|
7
|
+
spec.version = '1.0.1'
|
8
|
+
spec.authors = ["Charles Chamberlain"]
|
9
|
+
spec.email = ["charles@charlesetc.com"]
|
10
|
+
spec.description = %q{Benchm is the simplest way to time your programs.}
|
11
|
+
spec.summary = %q{Benchm is the simplest way to time your programs.}
|
12
|
+
spec.homepage = "https://github.com/Charlesetc/benchm"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
end
|
data/lib/benchm.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
module Benchm
|
3
|
+
|
4
|
+
@repeat = 1
|
5
|
+
|
6
|
+
def self.ark(message = nil, repeat = @repeat)
|
7
|
+
if repeat.class == Float
|
8
|
+
raise ArgumentError, "No implicit conversion of Float to Integer."
|
9
|
+
end
|
10
|
+
if message.class == Fixnum
|
11
|
+
repeat = message
|
12
|
+
message = nil
|
13
|
+
elsif message.class != String && message
|
14
|
+
raise ArgumentError, "No implicit conversion of #{message.class} to String."
|
15
|
+
end
|
16
|
+
time_1 = Time.now
|
17
|
+
repeat.to_i.times do
|
18
|
+
yield
|
19
|
+
end
|
20
|
+
time_2 = Time.now
|
21
|
+
puts
|
22
|
+
print message.capitalize + ' ' if message
|
23
|
+
print 'Total: '
|
24
|
+
puts (time_2 - time_1).to_s + ' seconds'
|
25
|
+
print message.capitalize + ' ' if message
|
26
|
+
print 'Average: '
|
27
|
+
puts ((time_2 - time_1)/repeat.to_f).to_s + ' seconds'
|
28
|
+
puts
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.repeat=(r)
|
32
|
+
unless r.class == Fixnum
|
33
|
+
raise ArgumentError, 'Repeat must be an integer.'
|
34
|
+
end
|
35
|
+
@repeat = r
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.repeat
|
39
|
+
@repeat
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: benchm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Charles Chamberlain
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Benchm is the simplest way to time your programs.
|
14
|
+
email:
|
15
|
+
- charles@charlesetc.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .gitignore
|
21
|
+
- LICENSE.txt
|
22
|
+
- README.md
|
23
|
+
- benchm.gemspec
|
24
|
+
- lib/benchm.rb
|
25
|
+
homepage: https://github.com/Charlesetc/benchm
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.0.5
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Benchm is the simplest way to time your programs.
|
49
|
+
test_files: []
|
50
|
+
has_rdoc:
|