timeit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/examples/duration.rb +14 -0
- data/examples/splits.rb +22 -0
- data/lib/timeit.rb +66 -0
- data/lib/timeit/version.rb +3 -0
- data/timeit.gemspec +26 -0
- metadata +89 -0
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
|
19
|
+
# YARD artifacts
|
20
|
+
.yardoc
|
21
|
+
_yardoc
|
22
|
+
doc/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 rainkinz
|
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,31 @@
|
|
1
|
+
timeit
|
2
|
+
======
|
3
|
+
|
4
|
+
Simple ruby timer
|
5
|
+
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'timeit'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install timeit
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
require 'timeit'
|
3
|
+
|
4
|
+
Timeit.ti do |timer|
|
5
|
+
1.upto(100) do |i|
|
6
|
+
if i % 10 == 0
|
7
|
+
timer.tick!(10)
|
8
|
+
puts "#{i} of 1000 in #{timer.duration} #{timer.rate} items/s"
|
9
|
+
end
|
10
|
+
sleep(0.1)
|
11
|
+
# timer.split! if i % 300 == 0
|
12
|
+
end
|
13
|
+
puts "Completed in #{timer.total_duration} "
|
14
|
+
end
|
data/examples/splits.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
require 'timeit'
|
3
|
+
|
4
|
+
Timeit.ti do |ti|
|
5
|
+
|
6
|
+
total_iterations = 100
|
7
|
+
1.upto(total_iterations) do |i|
|
8
|
+
if i % 10 == 0
|
9
|
+
ti.tick!(10)
|
10
|
+
puts "#{i} of #{total_iterations} in #{ti.duration} #{ti.rate} item/s"
|
11
|
+
end
|
12
|
+
|
13
|
+
if i % 20 == 0
|
14
|
+
puts "Split for the last 20 items was #{ti.split}, split rate #{ti.split_rate} items/s"
|
15
|
+
end
|
16
|
+
|
17
|
+
sleep(0.1)
|
18
|
+
end
|
19
|
+
puts "Completed in #{ti.total_duration} "
|
20
|
+
end
|
21
|
+
|
22
|
+
|
data/lib/timeit.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'timeit/version'
|
2
|
+
|
3
|
+
module Timeit
|
4
|
+
extend self
|
5
|
+
|
6
|
+
class Timer
|
7
|
+
|
8
|
+
attr_reader :start_time
|
9
|
+
|
10
|
+
def initialize(start = Time.now)
|
11
|
+
@start_time = start
|
12
|
+
@iterations = 0
|
13
|
+
@rate = 0
|
14
|
+
|
15
|
+
@split_time = start
|
16
|
+
@split_iterations = 0
|
17
|
+
@split_rate = 0
|
18
|
+
end
|
19
|
+
|
20
|
+
def duration
|
21
|
+
duration = Time.now - @start_time
|
22
|
+
@rate = @iterations / duration
|
23
|
+
duration
|
24
|
+
end
|
25
|
+
|
26
|
+
def total_duration
|
27
|
+
Time.now - @start_time
|
28
|
+
end
|
29
|
+
|
30
|
+
def split
|
31
|
+
split = Time.now - @split_time
|
32
|
+
@split_time = Time.now
|
33
|
+
|
34
|
+
@split_rate = @split_iterations / split
|
35
|
+
@split_iterations = 0
|
36
|
+
|
37
|
+
split
|
38
|
+
end
|
39
|
+
|
40
|
+
def reset_split!
|
41
|
+
@split_time = @start_time
|
42
|
+
end
|
43
|
+
|
44
|
+
def tick!(count = 1)
|
45
|
+
@iterations += count
|
46
|
+
@split_iterations += count
|
47
|
+
end
|
48
|
+
|
49
|
+
def rate
|
50
|
+
@rate
|
51
|
+
end
|
52
|
+
|
53
|
+
def split_rate
|
54
|
+
@split_rate
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def ti(&block)
|
61
|
+
t = Timer.new
|
62
|
+
yield t
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
data/timeit.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'timeit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "timeit"
|
8
|
+
spec.version = Timeit::VERSION
|
9
|
+
spec.authors = ["rainkinz"]
|
10
|
+
spec.email = ["brendan.grainger@gmail.com"]
|
11
|
+
spec.description = <<-TEXT
|
12
|
+
Very basic ruby timer for keeping track of the duration, splits and rate of
|
13
|
+
a block of code.
|
14
|
+
TEXT
|
15
|
+
spec.summary = %q{Track duration of a block of code}
|
16
|
+
spec.homepage = "https://github.com/rainkinz/timeit"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files`.split($/)
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: timeit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- rainkinz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: ! " Very basic ruby timer for keeping track of the duration, splits
|
47
|
+
and rate of\n a block of code.\n"
|
48
|
+
email:
|
49
|
+
- brendan.grainger@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- examples/duration.rb
|
60
|
+
- examples/splits.rb
|
61
|
+
- lib/timeit.rb
|
62
|
+
- lib/timeit/version.rb
|
63
|
+
- timeit.gemspec
|
64
|
+
homepage: https://github.com/rainkinz/timeit
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.23
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Track duration of a block of code
|
89
|
+
test_files: []
|