timed_report 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 145a3cc0df83810fe9e9195f3c75fe1986e69e9c
4
- data.tar.gz: c59286e6190f37a445560b42ae9d246fc59eccf6
3
+ metadata.gz: 664c1d4fdae3bbd2e849023c1e8116eb0bf4b1ac
4
+ data.tar.gz: 778bd0601f86f9ec1d52e0f9506141f8fed4e9ac
5
5
  SHA512:
6
- metadata.gz: 988b2b12d3f521042d8770074f782de7866f05afdc0c3660e1ce38dc61b0c82c6af3e4ad498783701ab7e187b6363b2a58a3329f6033becd869e9fd28eb5149b
7
- data.tar.gz: 1cfa0523a979b40c19128a3c6626a6e66293c2b0d53613b1a4d4414617ec0897c9b0cf4168dcfdb44523293cd91020ae9ed640b9cafd729af1593848d5517307
6
+ metadata.gz: 5aaba3f62b6682b60b8bc7886b030a5382b0bc6e367f2ed22526f5d081e0ca62fcc8c30067a87849853ef906d5db49b4c3b21e3166a2bcf66eb0619909488664
7
+ data.tar.gz: 388aeddf395bbf591e6b72e54542ed957a93f9c3366668e03579875483db10b77ffd9c4e5a61614b17a523a27c6f32aec64d38154fe992d82613cf9bd5a04102
@@ -0,0 +1,9 @@
1
+ require 'timed_report'
2
+
3
+ # Make the object, give it a name and set enabled to false
4
+ tr = TimedReport.new('This timed report is disabled', false)
5
+
6
+ tr.add('Sure?')
7
+
8
+ # This should print nothing
9
+ tr.finish()
@@ -19,6 +19,11 @@ sleep 0.5
19
19
  tr.time_step()
20
20
  tr.add('sleep 0.5 with time_step()')
21
21
 
22
+ 10.times do
23
+ sleep 0.1
24
+ tr.add_g("group test")
25
+ end
26
+
22
27
  # Export the report to the standard puts and the added method
23
28
  tr.finish()
24
29
 
data/lib/timed_report.rb CHANGED
@@ -95,10 +95,11 @@ class TimedReport
95
95
  # with_time: (Boolean)
96
96
  def add_g group, with_time = true
97
97
  return nil unless @enabled
98
- @groups[group.to_sym] ||= 0
98
+ @groups[group.to_sym] ||= {t:0,n:0}
99
99
 
100
100
  if with_time
101
- @groups[group.to_sym] += (Time.now - @step_time)
101
+ @groups[group.to_sym][:t] += (Time.now - @step_time)
102
+ @groups[group.to_sym][:n] += 1
102
103
  time_step()
103
104
  end
104
105
 
@@ -113,7 +114,7 @@ class TimedReport
113
114
  return nil unless @enabled
114
115
  @output += "\n--------------------------" if @groups.length > 0
115
116
  @groups.each do |k,v|
116
- @output += "\n#{k}: %.5f" % v
117
+ @output += "\n#{k}: %.5f (%d calls, %.5f avg.)" % [v[:t], v[:n], v[:t]/v[:n].to_f]
117
118
  end
118
119
  @output += "\n--------------------------"
119
120
  @output += "\nTotal time: %.5f" % (Time.now-@start_time)
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Aizenberg
@@ -18,6 +18,7 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - lib/timed_report.rb
20
20
  - example/simple_example.rb
21
+ - example/disabled_report.rb
21
22
  homepage: https://github.com/Tomtomgo/timed_report
22
23
  licenses:
23
24
  - MIT