walltime 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 +4 -4
- data/examples/2seconds.rb +1 -3
- data/examples/milliseconds.rb +97 -0
- data/lib/version.rb +14 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80995fe2cc8e7d72e5986edc4a563dc580a304d2
|
4
|
+
data.tar.gz: 97516c3e049c29b348d159a8c43bdcd5318b2508
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e0fe1ab3e178f657f6b82dafcce7cc8e3e26cee2112a1a3d4adc336169c120b597b218341e87689480528e9c98b4ff72231d47083dbfc6a9c23141deb28f36e
|
7
|
+
data.tar.gz: 7e4adb3188cdb2123f1246c313b41d3dd90e55834fee5ce55fee028fe889615bd74908432c2445d8e328d0aefaea6a73e5556d67bceb947bc470ae74f288668a
|
data/examples/2seconds.rb
CHANGED
@@ -0,0 +1,97 @@
|
|
1
|
+
########################################################################
|
2
|
+
#
|
3
|
+
# Author: Brian Hood
|
4
|
+
#
|
5
|
+
# Description: Milliseconds Example
|
6
|
+
#
|
7
|
+
# Display of Ruby refinements / Inheritance & Atomic Operation
|
8
|
+
# with Mutexes
|
9
|
+
########################################################################
|
10
|
+
|
11
|
+
|
12
|
+
require 'walltime'
|
13
|
+
|
14
|
+
unless RUBY_VERSION > "2.0"
|
15
|
+
puts "Refinements only work in 2.0 and above"
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
|
19
|
+
module TimeCustomize
|
20
|
+
|
21
|
+
refine Stopwatch do
|
22
|
+
|
23
|
+
def print_stats
|
24
|
+
round = round_to(@t2 - @t1, 2)
|
25
|
+
puts "Start: #{Time.at(@t1)} Finish: #{Time.at(@t2)} Total time: #{round}"
|
26
|
+
diff = (Time.at(@t2) - Time.at(@t1))*1000
|
27
|
+
puts "Difference: #{diff.to_s.gsub(".", "")[0..2]}ms"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
=begin
|
35
|
+
|
36
|
+
Its seems you can't inherit a class without a refinement and add one in your new class i.e
|
37
|
+
You don't see the refined version of print_stats just the original
|
38
|
+
|
39
|
+
class MyClock
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
class MyClockInherit < MyClock
|
44
|
+
|
45
|
+
using TimeCustomize
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
However you can inherit an existing one
|
50
|
+
|
51
|
+
class MyClock
|
52
|
+
|
53
|
+
using TimeCustomize
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
class MyClockInherit < MyClock; end
|
58
|
+
|
59
|
+
As below
|
60
|
+
=end
|
61
|
+
|
62
|
+
class MyClock
|
63
|
+
|
64
|
+
using TimeCustomize
|
65
|
+
|
66
|
+
def initialize
|
67
|
+
@a = Stopwatch.new
|
68
|
+
@a.watch('start')
|
69
|
+
end
|
70
|
+
|
71
|
+
def delay(seconds)
|
72
|
+
sleep(seconds)
|
73
|
+
end
|
74
|
+
|
75
|
+
def end
|
76
|
+
@a.watch('stop')
|
77
|
+
@a.print_stats
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
class MyClockInherit < MyClock; end
|
83
|
+
|
84
|
+
# Pass the Mutex a &block
|
85
|
+
m = Mutex.new
|
86
|
+
m.synchronize do
|
87
|
+
clock = MyClock.new
|
88
|
+
clock.delay(0.234)
|
89
|
+
clock.end
|
90
|
+
end
|
91
|
+
|
92
|
+
n = Mutex.new
|
93
|
+
n.synchronize do
|
94
|
+
clock = MyClockInherit.new
|
95
|
+
clock.delay(0.234)
|
96
|
+
clock.end
|
97
|
+
end
|
data/lib/version.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: walltime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Hood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Stopwatch you can use in all kinds of things
|
14
14
|
email: brianh6854@googlemail.com
|
@@ -17,6 +17,8 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- examples/2seconds.rb
|
20
|
+
- examples/milliseconds.rb
|
21
|
+
- lib/version.rb
|
20
22
|
- lib/walltime.rb
|
21
23
|
homepage: https://github.com/puppetpies/Walltime
|
22
24
|
licenses:
|