allotment 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 260e997e18de045d11302464320c034d157543ea
4
- data.tar.gz: d07b300e2acb0bdb7d9441117db692d5e3567cc3
3
+ metadata.gz: a732dd5ecc0207f646b2bf89f1bbc6adc3183ac9
4
+ data.tar.gz: 4ee65868e53130c4e6f253cd8db45b4507783717
5
5
  SHA512:
6
- metadata.gz: 8cbe37969369a29dcc2b000c42842c043c7d97996aba626b03861f96150d1a58f704ec475d125f66f6165348a6cd5e6e4adbf7809c2e87b92d266b623b60130d
7
- data.tar.gz: bbb47b9c27e82b8b1696f9b20766751daf8ba545e6b6714b9283a40e1ff7bebc3f193531ca4554461b5bfe94eb5e5af0ba62eba1f91599a67a1d4fbbf2e14541
6
+ metadata.gz: d7c21e210e1c779334d6c9423c013a525aec0e3c143715c94789690bc66174a74293a39ad9ffd8f4665d5f92d1ac36326c07ca541f866a60086417f7e782579a
7
+ data.tar.gz: ba69049b2c17d5efec5bd7570cba4a96d0f16e8ed81a4f9dfa3c980d32a80b5568bfc6e543b099473cb65a46ff01a413a5eb61437a31ba7acad68d0fe9303774
@@ -0,0 +1,52 @@
1
+ # History
2
+ ## Planned Versions
3
+ ### Version 1.1.0
4
+ #### Minor: Simplify, improve, clean
5
+ ##### Changed
6
+ * Rescue within an event to ensure that the timing is stopped in the event of a failure
7
+ * Remove old hooks and add new block management
8
+ * Remove and old or unrequired code
9
+ * Improved method naming
10
+ * Moved history and license into root
11
+
12
+ ##### Added
13
+ * Readme completed with hooks, stopwatches and now functionality
14
+ * 100% coverage rspec tests
15
+ * Complete commenting of code
16
+ * Added Rakefile and Tasks
17
+
18
+ ##### Fixed
19
+ * Updated Stopwatch
20
+ * Updated Stopwatch Specs
21
+
22
+ ### Version 1.0.4
23
+ #### Patch: Added before and after hooks
24
+ * Added before and after hooks
25
+ * Created hooks rspec tests
26
+ * Had to change allotment into class for hooks
27
+ * Split instance methods into seprate file
28
+ * Created release notes
29
+
30
+ ### Version 1.0.3
31
+ #### Patch: Updated and added files
32
+ * Updated Gemfile
33
+ * Updated gemspec
34
+ * Added Version
35
+ * Added Licence
36
+
37
+ ### Version 1.0.2
38
+ #### Patch: Results returned as Hashie::Mash
39
+ * results methods now return results as a Hashie::Mash
40
+
41
+ ### Version 1.0.1
42
+ #### Patch: Added instance methods
43
+ * Added instance methods so that the module can be included into a class and allotment does not need to be called every time.
44
+ * Cleaned up stopwatch so that it had lap and split
45
+
46
+ ## Released Versions
47
+ ### Version 1.0.0
48
+ #### Major: Inital release version.
49
+ * Allotment has the ablility to record blocks and procs, and to record from two separate points within the code.
50
+ * Stopwatch has been completed and can start, stop, split, lap and restart.
51
+ * There is an extention of Array for an average.
52
+ * There is Cucumber support, a cucumber file has been included that will record scenario and test time.
File without changes
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Allotment
1
+ ## "Time is what we want most, but what we use worst."
2
2
 
3
3
  [![Code Climate](https://codeclimate.com/github/benSlaughter/allotment.png)](https://codeclimate.com/github/benSlaughter/allotment)
4
4
  [![Build Status](https://travis-ci.org/benSlaughter/allotment.png?branch=master)](https://travis-ci.org/benSlaughter/allotment)
@@ -6,18 +6,31 @@
6
6
  [![Coverage Status](https://coveralls.io/repos/benSlaughter/allotment/badge.png?branch=master)](https://coveralls.io/r/benSlaughter/allotment)
7
7
  [![Gem Version](https://badge.fury.io/rb/allotment.png)](http://badge.fury.io/rb/allotment)
8
8
 
9
- Allotment is a performance rubygem that records and stores the performance timing of running a block of code,
10
- or from a from a chosen point, until a task or action is complete.
9
+ Allotment is a performance time recording gem.
10
+ It makes recording performance simple, while still being powerful and flexible.
11
11
 
12
- Each performance recording is stored with a recording name,
13
- each following recording is added so that multiple recordings can be queried and assesed.
12
+ Allotment gives you the ability to record the performance of code with ease, and all the while it will store all your results as your code runs.
13
+ Results can be acessed at any time from anywhere.
14
+ Recordings are grouped together under their name and an average of the results can be caluculated easily.
15
+ No threads where harmed in the making of this gem, no threads are used, and this makes Allotment lightweight and simple.
14
16
 
15
- Allotment also stores all the results so that they can be easily accessed at any time.
17
+ ### Cucumber
18
+
19
+ Allotment also plays well with cucumber.
20
+
21
+ A before and after hook records each scenarios completion time.
22
+
23
+ _See [Cucumber](#using-allotment-with-cucumber)_
24
+
25
+ ### Limitations
26
+
27
+ * Allotment cannot run two simultaneous recordings of the same name at the same time.
28
+ * Allotment has only one set of results and cannot record to diferent results. (e.g. performance and load)
16
29
 
17
30
  ## Setup
18
31
 
19
32
  Allotment has been tested with Ruby 1.9.2 and later.
20
- To install, type:
33
+ To install:
21
34
 
22
35
  ```bash
23
36
  gem install allotment
@@ -25,7 +38,8 @@ gem install allotment
25
38
 
26
39
  ## Using Allotment with Cucumber
27
40
 
28
- If you are using Cucumber you can record each scenario, and report the results to the console, add this line into your env.rb file:
41
+ If you are using Cucumber you can record each scenario.
42
+ Add this line into your env.rb file:
29
43
 
30
44
  ```ruby
31
45
  require 'allotment/cucumber'
@@ -33,70 +47,87 @@ require 'allotment/cucumber'
33
47
 
34
48
  ## Using Allotment
35
49
 
36
- Allotments main features are: the ability to record performance of ruby blocks; and record from point to point.
37
-
38
- Require Allotment at the start of your code:
50
+ Require Allotment at the start of your code
39
51
 
40
52
  ```ruby
41
53
  require 'allotment'
42
54
  ```
43
55
 
44
56
  ### Recording a Block
45
-
46
- The basic way of recording a block is as follows:
57
+ Recording a block of code could not be simpler.
47
58
 
48
59
  ```ruby
49
- Allotment.record_event('my_recording') { # code here }
60
+ Allotment.record('my_recording') { # code here }
50
61
  ```
51
62
  ```ruby
52
- Allotment.record_event('my_recording') do
63
+ Allotment.record('my_recording') do
53
64
  # code here
54
65
  end
55
66
  ```
56
67
 
57
- When an event has been completed the performance timing is returned by the method:
68
+ When an event has been completed the performance timing is returned by the method.
58
69
 
59
70
  ```ruby
60
- performance = Allotment.record_event { # code here }
71
+ performance = Allotment.record { # code here }
61
72
  ```
62
73
  ```ruby
63
- performance = Allotment.record_event do
74
+ performance = Allotment.record do
64
75
  # code here
65
76
  end
66
77
  ```
67
78
 
68
- ### Record point to point:
79
+ ### Record point to point
69
80
 
70
- The basic way of recording point to point is as follows:
81
+ Sometime you may want to record performance of more than just a block.
82
+ Allotment can do that too.
71
83
 
72
84
  ```ruby
73
- require 'allotment'
74
-
75
- Allotment.start_recording 'my_recording'
85
+ Allotment.start 'my_recording'
76
86
  # code here
77
- Allotment.stop_recording 'my_recording'
87
+ Allotment.stop 'my_recording'
78
88
  ```
79
89
 
80
- When stop recording is called the performance timing is returned by the method:
90
+ When stop is called the performance timing is returned by the method.
81
91
 
82
92
  ```ruby
83
- performance = Allotment.stop_recording 'my_recording'
93
+ performance = Allotment.stop 'my_recording'
84
94
  ```
85
95
 
86
- When start recording is called the timing stopwatch is returned by the method:
96
+ When start recording is called the timing stopwatch is returned by the method.
87
97
 
88
98
  ```ruby
89
- stopwatch = Allotment.start_recording 'my_recording'
99
+ stopwatch = Allotment.start 'my_recording'
90
100
  ```
91
101
 
92
102
  _More on [stopwatches](#allotment-stopwatches)_
93
103
 
94
- If a recording name does not exists, then a NameError shall be raised.
104
+ **Warning!** If a recording name does not exists, then a NameError is raised.
105
+
106
+ ### Hooks
107
+
108
+ Allotment has two inbuilt hooks, on_start, and on_stop.
109
+ Each hook contains a single proc that is called at points within recordings.
110
+
111
+ The on_start hook is called before the timer is started.
112
+ The on_stop hook is called after the timer is stopped.
113
+
114
+ A hook can be redefined at any time.
115
+ To define a hook call the hook and pass in a proc.
116
+
117
+ ```ruby
118
+ Allotment.on_start { # Extra code here }
119
+ ```
120
+ ```ruby
121
+ Allotment.on_start do
122
+ # Extra code here
123
+ end
124
+ ```
95
125
 
96
126
  ### Accessing performance results
97
127
 
98
- Performance recordings are stored within a hash. The reperformance results are logged to an array under the recording name.
99
- They can be access from Allotment at any time:
128
+ Allotment stores all the performance recordings as and when they happen.
129
+ If multiple recording of the same event exist they are stored in an array.
130
+ Allotment also patches Array with an average function.
100
131
 
101
132
  ```ruby
102
133
  hash = Allotment.results
@@ -111,7 +142,64 @@ result = Allotment.results["my_recording"].first
111
142
  result = Allotment.results["my_recording"].average
112
143
  ```
113
144
 
114
- ### Allotment Stopwatches
145
+ ## Allotment Stopwatches
146
+
147
+ Stopwatches are what Allotment uses to keep track of time.
148
+ Strangely enough they act just like a stopwatch.
149
+
150
+ ### Basic usage
151
+
152
+ Stopwatches live inside the Allotment module.
153
+ When created, a stopwatch is not running, however the start method returns the stopwatch, and so can be called inline.
154
+
155
+ ```ruby
156
+ sw = Allotment::Stopwatch.new
157
+ ```
158
+ ```ruby
159
+ sw = Allotment::Stopwatch.new.start
160
+ ```
161
+
162
+ When stopping a stopwatch, the time that is currently on the stopwatch is returned
163
+
164
+ ```ruby
165
+ time = sw.stop
166
+ ```
167
+
168
+ Reset will wipe all times clean, and completely reset the time.
169
+ Reset can be called at any time.
170
+
171
+ ```ruby
172
+ sw.reset
173
+ ```
174
+
175
+ ### Advanced usage
176
+
177
+ A stopwatch has the ability to lap, spit, and view the current time.
178
+ Each method behaves in a slightly different way.
179
+ * Lap is the time elapsed from the last time a lap was called.
180
+ * Split is the time from the last time the stopwatch was started.
181
+ * Time is the total time from when the stopwatch was first started.
182
+
183
+ When the stop watch is run and the methods are called.
184
+ ```
185
+ 30 seconds
186
+ start end
187
+ |--------------------------|
188
+ Lap |---10---|---10---|---10---|
189
+ Split |---10---|---20---|---30---|
190
+ Time |---10---|---20---|---30---|
191
+ ```
192
+
193
+ When the stopwatch is stopped and the methods are called.
194
+ ```
195
+ 30 seconds with 10 second stop
196
+ start
197
+ Lap |---10---| |---10---|
198
+ Split |---10---| |---10---|
199
+ Time |---10---| |---20---|
200
+ ```
115
201
 
116
- TODO
202
+ ## Notes
117
203
 
204
+ Stopwatches use ruby Time to calculate the time between a start and a stop.
205
+ Allotment rspec tests need to be improved upon.
@@ -1,49 +1,84 @@
1
+ require 'json'
2
+ require 'hashie'
3
+
1
4
  require 'allotment/array'
2
5
  require 'allotment/stopwatch'
3
6
 
4
- require 'json'
5
- require 'hashie'
6
- require 'hooks'
7
-
8
- class Allotment
9
- include Hooks
10
- define_hooks :before, :after
11
-
12
- class << self
13
- def record_event name = 'unnamed', &block
14
- start_recording name
15
- begin
16
- yield
17
- ensure
18
- time = stop_recording name
19
- end
20
- return time
21
- end
22
-
23
- def start_recording name = 'unnamed'
24
- run_hook :before
25
- @watches ||= Hashie::Mash.new
26
- @watches[name] = Stopwatch.new name
27
- end
28
-
29
- def stop_recording name
30
- watch = @watches.delete(name) { |n| raise NameError, "No recording:" + n }
31
- result = watch.stop
32
- run_hook :after
33
-
34
- # Dealing with the results
35
- @results ||= Hashie::Mash.new
36
- @results[name] ||= Array.new
37
- @results[name] << result
38
- return result
39
- end
40
-
41
- def results
42
- @results
43
- end
44
-
45
- def results_string
46
- JSON.pretty_generate @results
47
- end
48
- end
7
+ # Allotment
8
+ # "Time is what we want most, but what we use worst."
9
+ #
10
+ # require 'allotment'
11
+ #
12
+ # Allotment.record 'my_event' do
13
+ # # code here
14
+ # end
15
+ #
16
+ # Allotment.start 'my_event'
17
+ # # code here
18
+ # Allotment.stop 'my_event'
19
+ #
20
+ module Allotment
21
+ @watches = Hashie::Mash.new
22
+ @results = Hashie::Mash.new
23
+
24
+ # Allotment module methods
25
+ class << self
26
+ # Called when a recording is started
27
+ # @return [Proc] the stored request proc
28
+ #
29
+ def on_start &block
30
+ block_given? ? @on_start = block : @on_start
31
+ end
32
+
33
+ # Called when a recording is stopped
34
+ # @return [Proc] the stored request proc
35
+ #
36
+ def on_stop &block
37
+ block_given? ? @on_stop = block : @on_stop
38
+ end
39
+
40
+ # Start recording
41
+ # @param name [String] the name of the event
42
+ #
43
+ def start name = 'unnamed_recording'
44
+ on_start.call if on_start
45
+ @watches[name] = Stopwatch.new(name).start
46
+ end
47
+
48
+ # Stop recording
49
+ # @param name [String] the name of the event
50
+ # @raise [NameError] if the recording does not exist
51
+ #
52
+ def stop name
53
+ result = @watches.delete(name){ |n| raise NameError, "Unknown recording:" + n }.stop
54
+ on_stop.call if on_stop
55
+
56
+ # Dealing with the results
57
+ @results[name] ||= Array.new
58
+ @results[name] << result
59
+ return result
60
+ end
61
+
62
+ # Record event
63
+ # Expects a block to be passed
64
+ # @param name [String] the name of the event
65
+ # @yield [] runs the event
66
+ #
67
+ def record name = 'unnamed_event'
68
+ start name
69
+ begin
70
+ yield
71
+ ensure
72
+ result = stop name
73
+ end
74
+ result
75
+ end
76
+
77
+ # Results at that present moment
78
+ # @return [Hashie::Mash] the current results
79
+ #
80
+ def results
81
+ @results
82
+ end
83
+ end
49
84
  end
@@ -1,4 +1,8 @@
1
+ # Ruby Array
1
2
  class Array
3
+ # If an array is all numbers
4
+ # This displayes the mean average
5
+ #
2
6
  def average
3
7
  inject(:+).to_f / size
4
8
  end
@@ -1,13 +1,9 @@
1
1
  require 'allotment'
2
2
 
3
3
  Before do |scenario|
4
- Allotment.start_recording scenario.title
4
+ Allotment.start scenario.title
5
5
  end
6
6
 
7
7
  After do |scenario|
8
- Allotment.stop_recording scenario.title
9
- end
10
-
11
- at_exit do
12
- puts Allotment.results_string
8
+ Allotment.stop scenario.title
13
9
  end