allotment 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/allotment.rb +30 -0
- data/spec/allotment_spec.rb +52 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f1725b9fb8ace6c575075d430991795aee92207d
|
4
|
+
data.tar.gz: b1e799ec1f2f1072399e51ba0784ced21533218f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3672fb2aad8b5955d92639dcc8365c53c6324028629dd40ffe6b486527d5c7d0b5486dd49fd616343f1f79d2d700452f118286e4693055a487715e2e3935b50
|
7
|
+
data.tar.gz: 7c66df8f6fc284a61c50ce889f437127e3dbaea13842bad80f89cfaa500a29b564ab6d52dc3ccd485ed6de45019d130d761f845bb4b27ea2700319975f6ff8a6
|
data/lib/allotment.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Allotment
|
2
|
+
class << self
|
3
|
+
def record_event name = Time.now.to_s, &block
|
4
|
+
start_time = Time.now
|
5
|
+
yield
|
6
|
+
Time.now - start_time
|
7
|
+
end
|
8
|
+
|
9
|
+
def start_recording name = Time.now.to_s
|
10
|
+
@watches ||= Hash.new
|
11
|
+
@watches[name] = Stopwatch.new name
|
12
|
+
@watches[name]
|
13
|
+
end
|
14
|
+
|
15
|
+
def stop_recording name
|
16
|
+
watch = @watches.delete(name) {|e| "%s does not exist!" % e }
|
17
|
+
Time.now - watch.start_time
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Stopwatch
|
22
|
+
attr_reader :name, :status, :start_time
|
23
|
+
|
24
|
+
def initialize name
|
25
|
+
@name = name
|
26
|
+
@status = 'running'
|
27
|
+
@start_time = Time.now
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
require './lib/allotment'
|
5
|
+
|
6
|
+
describe Allotment, "#record_event" do
|
7
|
+
it "records the time for the block" do
|
8
|
+
Allotment.record_event('name') { nil }
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns a float" do
|
12
|
+
result = Allotment.record_event('name') { nil }
|
13
|
+
result.class.should eq Float
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the execute time of the block" do
|
17
|
+
result = Allotment.record_event('name') { sleep 0.1 }
|
18
|
+
result.round(1).should eq 0.1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe Allotment, "#start_recording" do
|
23
|
+
it "returns a stopwatch instance" do
|
24
|
+
result = Allotment.start_recording
|
25
|
+
result.class.should eq Allotment::Stopwatch
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns a stopwatch with the given name" do
|
29
|
+
result = Allotment.start_recording
|
30
|
+
result.class.should eq Allotment::Stopwatch
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns a stopwatch that is 'running'" do
|
34
|
+
result = Allotment.start_recording 'my_recording'
|
35
|
+
result.name.should eq 'my_recording'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe Allotment, "#stop_recording" do
|
40
|
+
it "returns a float" do
|
41
|
+
Allotment.start_recording 'my_recording1'
|
42
|
+
result = Allotment.stop_recording 'my_recording1'
|
43
|
+
result.class.should eq Float
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns the execute time of the code" do
|
47
|
+
Allotment.start_recording 'my_recording2'
|
48
|
+
sleep 0.1
|
49
|
+
result = Allotment.stop_recording 'my_recording2'
|
50
|
+
result.round(1).should eq 0.1
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: allotment
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Slaughter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A gem for recording performance and timings of blocks or from point to
|
14
|
+
point
|
15
|
+
email: b.p.slaughter@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/allotment.rb
|
21
|
+
- spec/allotment_spec.rb
|
22
|
+
homepage: https://github.com/benSlaughter/allotment
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.0.3
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Allotment - performance recording
|
46
|
+
test_files:
|
47
|
+
- spec/allotment_spec.rb
|