timeit 0.0.3 → 0.0.4
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.
- checksums.yaml +7 -0
- data/README.md +47 -6
- data/examples/duration.rb +4 -5
- data/examples/splits.rb +2 -3
- data/examples/total_duration.rb +8 -0
- data/lib/timeit.rb +22 -6
- data/lib/timeit/version.rb +1 -1
- metadata +13 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6b30891cb1314f13e404d3af8d2f7ba4917417dd
|
4
|
+
data.tar.gz: ccb3885fb4d59994045fe698845ca632895303c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2dfd6f807264406db2b06d7ea8225bdd8f0fb2d0efae3f82dfb82a0af02db2b75d6c47061375ab466000f12c4003604fc12854b6be7b3386711e4b24b928a94f
|
7
|
+
data.tar.gz: 9bb1f6fabf0c008a652dcf3f9eb216efa88fdc1bad3b2408fe434c77bd3d225765de30d00e8481c58901ef53e6c8c7246e7c6042607d48337b07089f1f01b1c6
|
data/README.md
CHANGED
@@ -1,8 +1,52 @@
|
|
1
|
-
timeit
|
2
|
-
======
|
1
|
+
# timeit
|
3
2
|
|
4
|
-
Simple ruby timer
|
3
|
+
Simple ruby timer.
|
5
4
|
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
* Calculate the total duration
|
8
|
+
```ruby
|
9
|
+
timer = Timeit.ti do
|
10
|
+
sleep 1
|
11
|
+
end
|
12
|
+
puts "Completed in #{timer.total_duration}"
|
13
|
+
```
|
14
|
+
|
15
|
+
|
16
|
+
* Log the rate and count 'iterations'
|
17
|
+
```ruby
|
18
|
+
timer = Timeit.ti do |ti|
|
19
|
+
1.upto(100) do |i|
|
20
|
+
if i % 10 == 0
|
21
|
+
ti.tick!(10)
|
22
|
+
puts "#{ti.count} of 1000 in #{ti.duration} #{ti.rate} items/s"
|
23
|
+
end
|
24
|
+
sleep(0.1)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
puts "Completed in #{timer.total_duration} "
|
28
|
+
```
|
29
|
+
|
30
|
+
* Splits
|
31
|
+
```ruby
|
32
|
+
timer = Timeit.ti do |ti|
|
33
|
+
|
34
|
+
total_iterations = 100
|
35
|
+
1.upto(total_iterations) do |i|
|
36
|
+
if i % 10 == 0
|
37
|
+
ti.tick!(10)
|
38
|
+
puts "#{i} of #{total_iterations} in #{ti.duration} #{ti.rate} item/s"
|
39
|
+
end
|
40
|
+
|
41
|
+
if i % 20 == 0
|
42
|
+
puts "Split for the last 20 items was #{ti.split}, split rate #{ti.split_rate} items/s"
|
43
|
+
end
|
44
|
+
|
45
|
+
sleep(0.1)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
puts "Completed in #{timer.total_duration} "
|
49
|
+
```
|
6
50
|
|
7
51
|
## Installation
|
8
52
|
|
@@ -18,9 +62,6 @@ Or install it yourself as:
|
|
18
62
|
|
19
63
|
$ gem install timeit
|
20
64
|
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
TODO: Write usage instructions here
|
24
65
|
|
25
66
|
## Contributing
|
26
67
|
|
data/examples/duration.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
$:.unshift File.expand_path("../../lib", __FILE__)
|
2
2
|
require 'timeit'
|
3
3
|
|
4
|
-
Timeit.ti do |
|
4
|
+
timer = Timeit.ti do |ti|
|
5
5
|
1.upto(100) do |i|
|
6
6
|
if i % 10 == 0
|
7
|
-
|
8
|
-
puts "#{
|
7
|
+
ti.tick!(10)
|
8
|
+
puts "#{ti.count} of 1000 in #{ti.duration} #{ti.rate} items/s"
|
9
9
|
end
|
10
10
|
sleep(0.1)
|
11
|
-
# timer.split! if i % 300 == 0
|
12
11
|
end
|
13
|
-
puts "Completed in #{timer.total_duration} "
|
14
12
|
end
|
13
|
+
puts "Completed in #{timer.total_duration} "
|
data/examples/splits.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
$:.unshift File.expand_path("../../lib", __FILE__)
|
2
2
|
require 'timeit'
|
3
3
|
|
4
|
-
Timeit.ti do |ti|
|
5
|
-
|
4
|
+
timer = Timeit.ti do |ti|
|
6
5
|
total_iterations = 100
|
7
6
|
1.upto(total_iterations) do |i|
|
8
7
|
if i % 10 == 0
|
@@ -16,7 +15,7 @@ Timeit.ti do |ti|
|
|
16
15
|
|
17
16
|
sleep(0.1)
|
18
17
|
end
|
19
|
-
puts "Completed in #{ti.total_duration} "
|
20
18
|
end
|
19
|
+
puts "Completed in #{timer.total_duration} "
|
21
20
|
|
22
21
|
|
data/lib/timeit.rb
CHANGED
@@ -5,18 +5,28 @@ module Timeit
|
|
5
5
|
|
6
6
|
class Timer
|
7
7
|
|
8
|
+
IllegalStateError = Class.new(RuntimeError)
|
9
|
+
|
8
10
|
attr_reader :start_time, :count
|
9
11
|
|
10
|
-
def initialize
|
11
|
-
@start_time =
|
12
|
+
def initialize
|
13
|
+
@start_time = nil
|
12
14
|
@count = 0
|
13
15
|
@rate = 0
|
14
16
|
|
15
|
-
@split_time =
|
17
|
+
@split_time = nil
|
16
18
|
@split_count = 0
|
17
19
|
@split_rate = 0
|
18
20
|
end
|
19
21
|
|
22
|
+
def start
|
23
|
+
@start_time = @split_time = Time.now
|
24
|
+
end
|
25
|
+
|
26
|
+
def stop
|
27
|
+
@stop_time = Time.now
|
28
|
+
end
|
29
|
+
|
20
30
|
def duration
|
21
31
|
duration = Time.now - @start_time
|
22
32
|
@rate = @count / duration
|
@@ -24,7 +34,11 @@ module Timeit
|
|
24
34
|
end
|
25
35
|
|
26
36
|
def total_duration
|
27
|
-
|
37
|
+
if @stop_time
|
38
|
+
@stop_time - @start_time
|
39
|
+
else
|
40
|
+
raise(IllegalStateError, "Timer must be stopped for total duration")
|
41
|
+
end
|
28
42
|
end
|
29
43
|
|
30
44
|
def split
|
@@ -56,10 +70,12 @@ module Timeit
|
|
56
70
|
|
57
71
|
end
|
58
72
|
|
59
|
-
|
60
|
-
def ti(&block)
|
73
|
+
def ti(autostart = true, &block)
|
61
74
|
t = Timer.new
|
75
|
+
t.start if autostart
|
62
76
|
yield t
|
77
|
+
t.stop
|
78
|
+
t
|
63
79
|
end
|
64
80
|
|
65
81
|
end
|
data/lib/timeit/version.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timeit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- rainkinz
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-06
|
11
|
+
date: 2013-08-06 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,21 +27,20 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
|
-
description:
|
47
|
-
|
41
|
+
description: |2
|
42
|
+
Very basic ruby timer for keeping track of the duration, splits and rate of
|
43
|
+
a block of code.
|
48
44
|
email:
|
49
45
|
- brendan.grainger@gmail.com
|
50
46
|
executables: []
|
@@ -58,32 +54,32 @@ files:
|
|
58
54
|
- Rakefile
|
59
55
|
- examples/duration.rb
|
60
56
|
- examples/splits.rb
|
57
|
+
- examples/total_duration.rb
|
61
58
|
- lib/timeit.rb
|
62
59
|
- lib/timeit/version.rb
|
63
60
|
- timeit.gemspec
|
64
61
|
homepage: https://github.com/rainkinz/timeit
|
65
62
|
licenses:
|
66
63
|
- MIT
|
64
|
+
metadata: {}
|
67
65
|
post_install_message:
|
68
66
|
rdoc_options: []
|
69
67
|
require_paths:
|
70
68
|
- lib
|
71
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
70
|
requirements:
|
74
|
-
- -
|
71
|
+
- - '>='
|
75
72
|
- !ruby/object:Gem::Version
|
76
73
|
version: '0'
|
77
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
-
none: false
|
79
75
|
requirements:
|
80
|
-
- -
|
76
|
+
- - '>='
|
81
77
|
- !ruby/object:Gem::Version
|
82
78
|
version: '0'
|
83
79
|
requirements: []
|
84
80
|
rubyforge_project:
|
85
|
-
rubygems_version:
|
81
|
+
rubygems_version: 2.0.3
|
86
82
|
signing_key:
|
87
|
-
specification_version:
|
83
|
+
specification_version: 4
|
88
84
|
summary: Track duration of a block of code
|
89
85
|
test_files: []
|