light_stopwatch 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/light_stopwatch.rb +29 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6af65a9ba5b43318a9e2643dcdd3a969af6c0a42
4
- data.tar.gz: f0ede6b50b91df6e340b48e1e50d8a7cfa4da495
3
+ metadata.gz: 73f3e5091ed44bf0ba0fb08d4b67e5f13cda7ef2
4
+ data.tar.gz: 7e13d8e5d9a248a3a100d3b153d0f34b2c3929ea
5
5
  SHA512:
6
- metadata.gz: 7a6bf8767d3f950314d770a93cd01e50b0ca1c5810de24f367b56e7dc1c10c10e24f6c3c81c3917049edb268eeaa7f71a2a47302025cde1751ea583247061636
7
- data.tar.gz: ee8769494c1245b268c0546f0c4e7a31c9522ca3eff173dcbc5ec6245196d7c3152bf7ddddc60648469ff3658a41d8fee5a29f15ebeb79fe19aa9d18479a404d
6
+ metadata.gz: 39beca2c9176eba42a00c4442a83ecb4e25577fbfa7747174e3e8ed8243afc3115856d91d230c654fd1511e03980124a75048441025bac5af6c2ab30136edb28
7
+ data.tar.gz: ae11be066ebd31418a833aaccf4a7d64bbc98c0e3631ef96081c59827f53049378d7157371f21d5cf2ae6fe0e4e35df79d5186e65434dd47c79c3ba8576f73db
@@ -1,12 +1,32 @@
1
- module LightStopwatch
1
+ class LightStopwatch
2
2
  DEFAULT_TAG = 'Operation took:'
3
+ @@ls_aggs = {}
3
4
 
4
- def get_time(&block)
5
- LightStopwatch.get_time(&block)
5
+ def self.agg_template
6
+ {value: 0, count: 0}
6
7
  end
7
8
 
8
- def measure(tag = DEFAULT_TAG, &block)
9
- LightStopwatch.measure(tag, &block)
9
+ def self.agg(key, &block)
10
+ @@ls_aggs[key] ||= agg_template
11
+
12
+ @@ls_aggs[key][:count] += 1
13
+ @@ls_aggs[key][:value] += get_time(&block)
14
+ end
15
+
16
+ def self.get_aggs
17
+ @@ls_aggs
18
+ end
19
+
20
+ def self.get_agg(key)
21
+ @@ls_aggs[key]
22
+ end
23
+
24
+ def self.get_agg_count(key)
25
+ @@ls_aggs[key] && @@ls_aggs[key][:count]
26
+ end
27
+
28
+ def self.get_agg_value(key)
29
+ @@ls_aggs[key] && @@ls_aggs[key][:value]
10
30
  end
11
31
 
12
32
  def self.get_time(&block)
@@ -20,6 +40,10 @@ module LightStopwatch
20
40
  def self.measure(tag = DEFAULT_TAG, &block)
21
41
  puts "#{tag} #{get_time(&block)}"
22
42
  end
43
+
44
+ def self.reset
45
+ @@ls_aggs = {}
46
+ end
23
47
  end
24
48
 
25
49
  LS = LightStopwatch
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: light_stopwatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Renra Gloser