quicky 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- quicky (0.0.2)
4
+ quicky (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -0,0 +1,51 @@
1
+ Quicky if for easily timing chunks of code.
2
+
3
+ ## Getting Started
4
+
5
+ gem install quicky
6
+
7
+ ## Timing
8
+
9
+ ### Time anything
10
+
11
+ ```ruby
12
+ quicky = Quicky::Timer.new
13
+ quicky.time(:test1) do
14
+ sleep 2
15
+ end
16
+ # Print average duration for all :test1 timings
17
+ p quicky.results(:test1).duration
18
+ # Print total duration for all :test1 timings
19
+ p quicky.results(:test1).total_duration
20
+ # Print longest duration for all :test1 timings
21
+ p quicky.results(:test1).max_duration
22
+ # Print shortest duration for all :test1 timings
23
+ p quicky.results(:test1).min_duration
24
+
25
+ ### Time in a loop
26
+
27
+ Good for performance testing.
28
+
29
+ ```ruby
30
+ quicky = Quicky::Timer.new
31
+ # This will loop 10 times
32
+ quicky.loop(:test2, 10) do |i|
33
+ puts 'sleeping'
34
+ sleep 1
35
+ end
36
+ ```
37
+
38
+ Or loop for X seconds:
39
+
40
+ ```ruby
41
+ # This will loop for 10 seconds
42
+ quicky.loop_for(:test3, 10) do |i|
43
+ puts 'sleeping'
44
+ sleep 0.5
45
+ end
46
+ ```
47
+
48
+ #### Looping Options
49
+
50
+ - warmup: X -- will throw out the first X results.
51
+
@@ -52,16 +52,22 @@ module Quicky
52
52
  end
53
53
 
54
54
  class TimeCollector
55
+ INT_MAX = ( (2 ** (32 - 2)) - 1 )
56
+
55
57
  attr_accessor :name
56
58
  def initialize(name)
57
59
  @name = name
58
60
  @collector = []
59
61
  @total_duration = 0.0
62
+ @max_duration = 0.0
63
+ @min_duration = INT_MAX
60
64
  end
61
65
 
62
66
  def <<(val)
63
67
  # pull out duration for totals
64
68
  @total_duration += val.duration
69
+ @max_duration = val.duration if val.duration > @max_duration
70
+ @min_duration = val.duration if val.duration < @min_duration
65
71
  @collector << val
66
72
  end
67
73
 
@@ -73,6 +79,14 @@ module Quicky
73
79
  @total_duration
74
80
  end
75
81
 
82
+ def max_duration
83
+ @max_duration
84
+ end
85
+
86
+ def min_duration
87
+ @min_duration
88
+ end
89
+
76
90
  def count
77
91
  @collector.size
78
92
  end
@@ -1,3 +1,3 @@
1
1
  module Quicky
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -33,11 +33,15 @@ class TestBasics < TestBase
33
33
  puts 'sleeping'
34
34
  sleep 0.5
35
35
  end
36
- p quicky.results(:test3).inspect
37
- p quicky.results(:test3).duration
36
+ result = quicky.results(:test3)
37
+ p result.inspect
38
+ p result.duration
38
39
  p quicky.results.count
39
- assert quicky.results(:test3).duration >= 0.5 && quicky.results(:test3).duration < 1
40
- assert quicky.results(:test3).total_duration >= 5
40
+ assert result.duration >= 0.5 && result.duration < 1
41
+ assert result.total_duration >= 5
42
+ assert result.min_duration < 0.55 && result.min_duration > 0.1
43
+ assert result.max_duration > 0.5 && result.max_duration < 0.7
44
+
41
45
 
42
46
  end
43
47
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quicky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-28 00:00:00.000000000 Z
12
+ date: 2012-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: test-unit