timed_report 0.0.5 → 0.0.6

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: 8121bacc016d30f43c763990475d37b1c679a6ff
4
- data.tar.gz: 5d905cf04ede060e761982336270d2e4deb2351c
3
+ metadata.gz: 145a3cc0df83810fe9e9195f3c75fe1986e69e9c
4
+ data.tar.gz: c59286e6190f37a445560b42ae9d246fc59eccf6
5
5
  SHA512:
6
- metadata.gz: 1bc300f56cc6dc5aff930e74b4b80fdb88c7657cac840e0b2706edc14d2964431d555021b9ccab207f6bf51a74c8730efdda9b276d1785d02d3cc05bf9825ed8
7
- data.tar.gz: b292258ebc5498190c7354230c13e034d009de323dd943c8cb69e25415a110c8254fbebf45709b66faeaa83fdddc7b53180c4feb4286ce97124c2229107f97f7
6
+ metadata.gz: 988b2b12d3f521042d8770074f782de7866f05afdc0c3660e1ce38dc61b0c82c6af3e4ad498783701ab7e187b6363b2a58a3329f6033becd869e9fd28eb5149b
7
+ data.tar.gz: 1cfa0523a979b40c19128a3c6626a6e66293c2b0d53613b1a4d4414617ec0897c9b0cf4168dcfdb44523293cd91020ae9ed640b9cafd729af1593848d5517307
@@ -20,4 +20,5 @@ tr.time_step()
20
20
  tr.add('sleep 0.5 with time_step()')
21
21
 
22
22
  # Export the report to the standard puts and the added method
23
- tr.finish()
23
+ tr.finish()
24
+
data/lib/timed_report.rb CHANGED
@@ -9,12 +9,15 @@ class TimedReport
9
9
  #
10
10
  # Arguments:
11
11
  # named: (String)
12
- def initialize named = nil
12
+ # enabled: (boolean)
13
+ def initialize named = nil, enabled = true
14
+ @enabled = enabled
15
+ @groups = {}
13
16
  @intermediate_output = false
14
-
17
+
15
18
  @start_time = Time.now
16
19
  @step_time = Time.now
17
-
20
+
18
21
  @output = "\n=========================="
19
22
 
20
23
  if named != nil
@@ -30,6 +33,7 @@ class TimedReport
30
33
  # Arguments:
31
34
  # val: (Boolean)
32
35
  def intermediate_output val = @intermediate_output
36
+ return nil unless @enabled
33
37
  @intermediate_output = val
34
38
  val
35
39
  end
@@ -44,6 +48,7 @@ class TimedReport
44
48
  # Arguments:
45
49
  # method: (Proc or lambda)
46
50
  def add_output_method method
51
+ return nil unless @enabled
47
52
  @output_methods.push method
48
53
  end
49
54
 
@@ -52,6 +57,7 @@ class TimedReport
52
57
  # Example:
53
58
  # >> tr.time_step()
54
59
  def time_step
60
+ return nil unless @enabled
55
61
  @step_time = Time.now
56
62
  "❤"
57
63
  end
@@ -65,6 +71,7 @@ class TimedReport
65
71
  # txt: (String)
66
72
  # with_time: (Boolean)
67
73
  def add txt, with_time = true
74
+ return nil unless @enabled
68
75
  if with_time
69
76
  timing_info = "%.5f: " % (Time.now - @step_time)
70
77
  time_step()
@@ -78,11 +85,36 @@ class TimedReport
78
85
  "❤"
79
86
  end
80
87
 
88
+ # Adds a time count with key between the last #add or #add_g or #time_step.
89
+ #
90
+ # Example:
91
+ # >> tr.add_g("one step")
92
+ #
93
+ # Arguments:
94
+ # group: (String)
95
+ # with_time: (Boolean)
96
+ def add_g group, with_time = true
97
+ return nil unless @enabled
98
+ @groups[group.to_sym] ||= 0
99
+
100
+ if with_time
101
+ @groups[group.to_sym] += (Time.now - @step_time)
102
+ time_step()
103
+ end
104
+
105
+ "❤"
106
+ end
107
+
81
108
  # Finish the report. Call this add the end to print the report!
82
109
  #
83
110
  # Example:
84
111
  # >> tr.finish()
85
112
  def finish
113
+ return nil unless @enabled
114
+ @output += "\n--------------------------" if @groups.length > 0
115
+ @groups.each do |k,v|
116
+ @output += "\n#{k}: %.5f" % v
117
+ end
86
118
  @output += "\n--------------------------"
87
119
  @output += "\nTotal time: %.5f" % (Time.now-@start_time)
88
120
  @output += "\n=========================="
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timed_report
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Aizenberg