era 0.0.3
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/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/era.gemspec +22 -0
- data/lib/era.rb +20 -0
- data/lib/era/kernel.rb +5 -0
- data/lib/era/version.rb +3 -0
- data/test/era_test.rb +11 -0
- data/test/helper.rb +3 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 17ea878c7cb6144b1c78bf7c8032b1f3fe434c3e
|
4
|
+
data.tar.gz: b40292b53a03244cbd9148fd7d3411323e6cdea6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fac92980073ff423a46cbcee5aa4f60f75ee01d0f794df143796125fb39265abec5badb892c94ea73156c7fd5b30cff71995139007fbce49ff1fee3eb874e5c7
|
7
|
+
data.tar.gz: 28db51afbc6892cf6552f5d951d3c71d0bbff0b4cbe5554aa0fc83e17f3731052488a73cd1b967a2508b62b8aa01a17beef2598470df1c9085ffdcd76ec94905
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Shannon Skipper
|
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,44 @@
|
|
1
|
+
# Era
|
2
|
+
Era is just a pinch of benchmarking sugar in the form of a gem. It prints the time a block takes to execute but still returns its original return value.
|
3
|
+
|
4
|
+
Era is inspired by Clojure's `time` benchmarking function, which very similarly prints the time it took to exectue but returns the expression's value. Era also gives the option to specify the number of times to run the block but still returns the value from the last run.
|
5
|
+
|
6
|
+
Era adds the `Era.time` method to `Kernel` so you can just `time do` instead of `Era.time do` to benchmark your block.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
```ruby
|
10
|
+
require 'era'
|
11
|
+
|
12
|
+
time do
|
13
|
+
sleep 2
|
14
|
+
1 + 1
|
15
|
+
end
|
16
|
+
#>> Elapsed time: 2.000202 ms
|
17
|
+
#=> 2
|
18
|
+
```
|
19
|
+
```ruby
|
20
|
+
require 'era'
|
21
|
+
|
22
|
+
time(1_000_000) { 1 + 1 }
|
23
|
+
#>> Elapsed time: 0.081605 ms
|
24
|
+
#=> 2
|
25
|
+
```
|
26
|
+
```ruby
|
27
|
+
require 'era'
|
28
|
+
|
29
|
+
time 1000 do
|
30
|
+
(99 ** 99) / (88 ** 88)
|
31
|
+
end
|
32
|
+
#>> Elapsed time: 0.039134 ms
|
33
|
+
#=> 284059367663871701169263886
|
34
|
+
```
|
35
|
+
|
36
|
+
## Installation
|
37
|
+
```bash
|
38
|
+
gem install era
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
1. Fork it
|
43
|
+
2. Commit changes
|
44
|
+
3. Pull request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/era.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'era/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'era'
|
8
|
+
spec.version = Era::VERSION
|
9
|
+
spec.authors = ['Shannon Skipper']
|
10
|
+
spec.email = ['shannonskipper@gmail.com']
|
11
|
+
spec.description = %q{Print the time a block takes but still return its value.}
|
12
|
+
spec.summary = %q{Evaluates a block and prints the time it took. Returns the block value. Takes an optional argument for number of times to run the block.}
|
13
|
+
spec.homepage = 'https://github.com/havenwood/era#readme'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.4'
|
20
|
+
spec.add_development_dependency 'rake'
|
21
|
+
spec.add_development_dependency 'minitest'
|
22
|
+
end
|
data/lib/era.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'era/version'
|
2
|
+
require 'era/kernel'
|
3
|
+
require 'benchmark'
|
4
|
+
|
5
|
+
module Era
|
6
|
+
##
|
7
|
+
# Evaluates a block and prints the time it took. Returns the block value.
|
8
|
+
# Takes an optional argument for number of times to run the block.
|
9
|
+
def self.time this_many = 1
|
10
|
+
value = nil
|
11
|
+
s = Benchmark.realtime do
|
12
|
+
this_many.pred.times do
|
13
|
+
yield
|
14
|
+
end
|
15
|
+
value = yield
|
16
|
+
end
|
17
|
+
puts "Elapsed time: #{s * 1000} ms"
|
18
|
+
value
|
19
|
+
end
|
20
|
+
end
|
data/lib/era/kernel.rb
ADDED
data/lib/era/version.rb
ADDED
data/test/era_test.rb
ADDED
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: era
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shannon Skipper
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.4'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Print the time a block takes but still return its value.
|
56
|
+
email:
|
57
|
+
- shannonskipper@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- era.gemspec
|
68
|
+
- lib/era.rb
|
69
|
+
- lib/era/kernel.rb
|
70
|
+
- lib/era/version.rb
|
71
|
+
- test/era_test.rb
|
72
|
+
- test/helper.rb
|
73
|
+
homepage: https://github.com/havenwood/era#readme
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.1.8
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Evaluates a block and prints the time it took. Returns the block value. Takes
|
97
|
+
an optional argument for number of times to run the block.
|
98
|
+
test_files: []
|
99
|
+
has_rdoc:
|