quicky 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- quicky (0.1.0)
4
+ quicky (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- test-unit (2.5.1)
9
+ test-unit (2.5.2)
10
10
 
11
11
  PLATFORMS
12
12
  ruby
data/README.md CHANGED
@@ -13,6 +13,11 @@ quicky = Quicky::Timer.new
13
13
  quicky.time(:test1) do
14
14
  sleep 2
15
15
  end
16
+ ```
17
+
18
+ Call time over and over again and when ready for results:
19
+
20
+ ```ruby
16
21
  # Print average duration for all :test1 timings
17
22
  p quicky.results(:test1).duration
18
23
  # Print total duration for all :test1 timings
@@ -21,6 +26,7 @@ p quicky.results(:test1).total_duration
21
26
  p quicky.results(:test1).max_duration
22
27
  # Print shortest duration for all :test1 timings
23
28
  p quicky.results(:test1).min_duration
29
+ ```
24
30
 
25
31
  ### Time in a loop
26
32
 
@@ -49,3 +55,34 @@ end
49
55
 
50
56
  - warmup: X -- will throw out the first X results.
51
57
 
58
+ ## Results
59
+
60
+ You can get all the results with:
61
+
62
+ ```ruby
63
+ results = quicky.results
64
+ ```
65
+
66
+ Or a single result:
67
+
68
+ ```ruby
69
+ result = quicky.results(:test1)
70
+ ```
71
+
72
+ Or turn it into a straight up hash:
73
+
74
+ ```ruby
75
+ hash = quicky.results.to_hash
76
+ ```
77
+
78
+ And even marshal a hash back into a quicky objects:
79
+
80
+ ```ruby
81
+ results = Quicky::ResultsHash.from_hash(hash)
82
+ ```
83
+
84
+ Or merge several results hashes together (if you were doing some tests in parallel):
85
+
86
+ ```ruby
87
+ results.merge!(other_results)
88
+ ```
@@ -5,11 +5,32 @@ module Quicky
5
5
  # returns results in a straight up hash.
6
6
  def to_hash
7
7
  ret = {}
8
- self.each_pair do |k,v|
8
+ self.each_pair do |k, v|
9
9
  ret[k] = v.to_hash()
10
10
  end
11
11
  ret
12
12
  end
13
+
14
+ # if given the same results from to_hash, this will recreate the ResultsHash
15
+ def self.from_hash(h)
16
+ rh = ResultsHash.new
17
+ h.each_pair do |k, v|
18
+ rh[k] = TimeCollector.from_hash(v)
19
+ end
20
+ rh
21
+ end
22
+
23
+ # merges multiple ResultsHash's
24
+ def merge!(rh)
25
+ rh.each_pair do |k, v|
26
+ # v is a TimeCollector
27
+ if self.has_key?(k)
28
+ self[k].merge!(v)
29
+ else
30
+ self[k] = v
31
+ end
32
+ end
33
+ end
13
34
  end
35
+ end
14
36
 
15
- end
@@ -56,7 +56,7 @@ module Quicky
56
56
  class TimeCollector
57
57
  INT_MAX = ((2 ** (32 - 2)) - 1)
58
58
 
59
- attr_accessor :name
59
+ attr_accessor :name, :total_duration, :count, :max_duration, :min_duration
60
60
 
61
61
  def initialize(name)
62
62
  @name = name
@@ -64,34 +64,24 @@ module Quicky
64
64
  @total_duration = 0.0
65
65
  @max_duration = 0.0
66
66
  @min_duration = INT_MAX
67
+ @count = 0
67
68
  end
68
69
 
69
70
  def <<(val)
70
71
  # pull out duration for totals
71
72
  @total_duration += val.duration
72
- @max_duration = val.duration if val.duration > @max_duration
73
- @min_duration = val.duration if val.duration < @min_duration
73
+ update_max_min(val.duration)
74
74
  @collector << val
75
+ @count += 1
75
76
  end
76
77
 
77
- def duration
78
- @total_duration / @collector.size
79
- end
80
-
81
- def total_duration
82
- @total_duration
83
- end
84
-
85
- def max_duration
86
- @max_duration
87
- end
88
-
89
- def min_duration
90
- @min_duration
78
+ def update_max_min(duration)
79
+ @max_duration = duration if duration > @max_duration
80
+ @min_duration = duration if duration < @min_duration
91
81
  end
92
82
 
93
- def count
94
- @collector.size
83
+ def duration
84
+ @total_duration / self.count
95
85
  end
96
86
 
97
87
  def to_hash
@@ -105,6 +95,21 @@ module Quicky
105
95
  }
106
96
  end
107
97
 
98
+ def self.from_hash(h)
99
+ t = TimeCollector.new(h['name'])
100
+ h.each_pair do |k,v|
101
+ t.instance_variable_set("@#{k}", v)
102
+ end
103
+ t
104
+ end
105
+
106
+ def merge!(tc)
107
+ self.count += tc.count
108
+ self.total_duration += tc.total_duration
109
+ update_max_min(tc.max_duration)
110
+ update_max_min(tc.min_duration)
111
+ end
112
+
108
113
  end
109
114
 
110
115
  class TimeResult
@@ -1,3 +1,3 @@
1
1
  module Quicky
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -5,7 +5,7 @@ Gem::Specification.new do |gem|
5
5
  gem.email = ["treeder@gmail.com"]
6
6
  gem.description = "Rest client wrapper that chooses best installed client."
7
7
  gem.summary = "Rest client wrapper that chooses best installed client."
8
- gem.homepage = "https://github.com/iron-io/quicky"
8
+ gem.homepage = "https://github.com/treeder/quicky"
9
9
 
10
10
  gem.files = `git ls-files`.split($\)
11
11
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -42,10 +42,20 @@ class TestBasics < TestBase
42
42
  assert result.min_duration < 0.55 && result.min_duration > 0.1
43
43
  assert result.max_duration > 0.5 && result.max_duration < 0.7
44
44
 
45
- hash = quicky.results.to_hash
45
+ r1 = quicky.results
46
+ p r1
47
+ hash = r1.to_hash
46
48
  p hash
47
49
  assert hash[:test3][:duration] >= 0.5
48
50
 
51
+ r2 = Quicky::ResultsHash.from_hash(hash)
52
+ p r2
53
+ assert_equal r1.size, r2.size
54
+ r1.each_pair do |k, v|
55
+ # v should be a TimeCollector
56
+ assert_equal v.count, r2[k].count
57
+ end
58
+
49
59
  end
50
60
 
51
61
  end
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.1.1
4
+ version: 0.2.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-08-14 00:00:00.000000000 Z
12
+ date: 2012-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: test-unit
@@ -47,7 +47,7 @@ files:
47
47
  - quicky.gemspec
48
48
  - test/test_base.rb
49
49
  - test/test_basics.rb
50
- homepage: https://github.com/iron-io/quicky
50
+ homepage: https://github.com/treeder/quicky
51
51
  licenses: []
52
52
  post_install_message:
53
53
  rdoc_options: []