walltime 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/examples/2seconds.rb +9 -0
  3. data/lib/walltime.rb +70 -0
  4. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ced9b8252e1d0cac79c1ef230d367cd5377b56f8
4
+ data.tar.gz: 2947dac03d3bca333f2a1191a5c469dfbe7355e5
5
+ SHA512:
6
+ metadata.gz: bc6917e0324ebbcedcfcc6ce88e638c3afc1f9e4d9a6e56195d6fd1c2b0a5c43c231a76139efbd55a88cd4d04845c50d03176e2ed31846395e68f4737eca8755
7
+ data.tar.gz: ba54bd81979ddbb106039b37099ec422e5a4b06e6dd7ba2c7c8f494ba3cd50095cfdf976dd0a637d743badc0ce758f6d2a4fe7e8e5baa395910327b11987e3ed
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.join(
2
+ File.dirname(__FILE__),
3
+ "../lib/stopwatch.rb"))
4
+
5
+ a = Stopwatch.new
6
+ a.watch('start')
7
+ sleep(2)
8
+ a.watch['stop')
9
+ a.print_stats
data/lib/walltime.rb ADDED
@@ -0,0 +1,70 @@
1
+ ########################################################################
2
+ #
3
+ # Author: Brian Hood
4
+ #
5
+ # Description: Walltime
6
+ #
7
+ # A stopwatch project for all kinds of things
8
+ #
9
+ ########################################################################
10
+
11
+ module NumTools
12
+
13
+ def random_between(min, max); min+rand(max); end
14
+
15
+ def self.define_component(name)
16
+ name_func = name.to_s.gsub("_to", "").to_sym
17
+ define_method(name) do |val, x|
18
+ (val * 10**x).send("#{name_func}").to_f / 10**x
19
+ end
20
+ end
21
+
22
+ define_component :floor_to
23
+ define_component :ceil_to
24
+ define_component :round_to
25
+
26
+ end
27
+
28
+ class Stopwatch
29
+
30
+ include NumTools
31
+
32
+ attr_reader :t1, :t2, :roundvals
33
+
34
+ private
35
+
36
+ def initialize
37
+ @roundvals = []
38
+ end
39
+
40
+ def intervalh
41
+ round = round_to(@t2 - @t1, 2)
42
+ t1h, t2h, @calc = Time.at(@t1), Time.at(@t2), round
43
+ record(round)
44
+ end
45
+
46
+ protected
47
+
48
+ def timestamp; Time.now.to_f; end
49
+
50
+ public
51
+
52
+ def record(round)
53
+ @roundvals << round
54
+ end
55
+
56
+ def print_stats
57
+ round = round_to(@t2 - @t1, 2)
58
+ puts "Start: #{Time.at(@t1)} Finish: #{Time.at(@t2)} Total time: #{round}"
59
+ end
60
+
61
+ def watch(method)
62
+ if method == "start"
63
+ @t1 = timestamp
64
+ elsif method == "stop"
65
+ @t2 = timestamp
66
+ intervalh
67
+ end
68
+ end
69
+
70
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: walltime
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Brian Hood
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Stopwatch you can use in all kinds of things
14
+ email: brianh6854@googlemail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - examples/2seconds.rb
20
+ - lib/walltime.rb
21
+ homepage: http://rubygems.org/gems/keycounter
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.2.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Walltime
45
+ test_files: []