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.
- checksums.yaml +4 -4
- data/lib/light_stopwatch.rb +29 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73f3e5091ed44bf0ba0fb08d4b67e5f13cda7ef2
|
4
|
+
data.tar.gz: 7e13d8e5d9a248a3a100d3b153d0f34b2c3929ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39beca2c9176eba42a00c4442a83ecb4e25577fbfa7747174e3e8ed8243afc3115856d91d230c654fd1511e03980124a75048441025bac5af6c2ab30136edb28
|
7
|
+
data.tar.gz: ae11be066ebd31418a833aaccf4a7d64bbc98c0e3631ef96081c59827f53049378d7157371f21d5cf2ae6fe0e4e35df79d5186e65434dd47c79c3ba8576f73db
|
data/lib/light_stopwatch.rb
CHANGED
@@ -1,12 +1,32 @@
|
|
1
|
-
|
1
|
+
class LightStopwatch
|
2
2
|
DEFAULT_TAG = 'Operation took:'
|
3
|
+
@@ls_aggs = {}
|
3
4
|
|
4
|
-
def
|
5
|
-
|
5
|
+
def self.agg_template
|
6
|
+
{value: 0, count: 0}
|
6
7
|
end
|
7
8
|
|
8
|
-
def
|
9
|
-
|
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
|