monotonic.rb 0.6.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9979d0a0e7fc996df84bf502588cf932d35fcfe43f963260688f38eb3e77e4fc
4
+ data.tar.gz: 9957c75ff1d0c716ee02b371e33567ef3a15f70c79cea01ca09d05c3496eed42
5
+ SHA512:
6
+ metadata.gz: d4920ceac6910df0a044a34ac5c903dd8de5e721e7046cde29bc0f6308b38930bc86e45df1cf359bb489ec47c7e025e8b5321103eb8a03f35935190c184a9252
7
+ data.tar.gz: 3e76c765f6382ed5a45098be13ad2e038dff7fde22279e06485398bf386d4267be17f12ab81c3f2abb0456e8468d09c3a641ddc9ab6923be1c6c39b07b3a9aea
@@ -0,0 +1,41 @@
1
+ # Monotonic/Time.rb
2
+ # Monotonic::Time
3
+
4
+ require 'sys-uptime'
5
+
6
+ module Monotonic
7
+ class Time
8
+
9
+ class << self
10
+
11
+ def now
12
+ self.new
13
+ end
14
+
15
+ end # class << self
16
+
17
+ attr_reader :seconds_since_boot
18
+
19
+ def initialize
20
+ @boot_time = Sys::Uptime.boot_time
21
+ @seconds_since_boot = Process.clock_gettime(Process::CLOCK_MONOTONIC)
22
+ end
23
+
24
+ def +(monotonic_time_addend)
25
+ @seconds_since_boot + monotonic_time_addend.seconds_since_boot
26
+ end
27
+
28
+ def -(monotonic_time_subtrahend)
29
+ @seconds_since_boot - monotonic_time_subtrahend.seconds_since_boot
30
+ end
31
+
32
+ def to_s
33
+ "#{@seconds_since_boot} seconds since boot."
34
+ end
35
+
36
+ def to_time
37
+ @boot_time + @seconds_since_boot
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,48 @@
1
+ # Monotonic::Timer.rb
2
+ # Monotonic::Timer
3
+
4
+ require_relative './Time'
5
+
6
+ module Monotonic
7
+ class Timer
8
+
9
+ class << self
10
+
11
+ def time
12
+ timer = Timer.new
13
+ timer.start
14
+ yield timer
15
+ ensure
16
+ timer.stop
17
+ timer.total_time
18
+ end
19
+
20
+ end # class << self
21
+
22
+ def start
23
+ @finish_time = nil
24
+ @start_time = Monotonic::Time.now
25
+ end
26
+
27
+ def stop
28
+ @finish_time = Monotonic::Time.now
29
+ end
30
+
31
+ def total_time
32
+ if @finish_time
33
+ @finish_time - @start_time
34
+ else
35
+ Monotonic::Time.now - @start_time
36
+ end
37
+ end
38
+
39
+ def time
40
+ start
41
+ yield self
42
+ ensure
43
+ stop
44
+ total_time
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,8 @@
1
+ # Monotonic/VERSION.rb
2
+ # Monotonic::VERSION
3
+
4
+ class Monotonic
5
+
6
+ VERSION = '0.6.0'
7
+
8
+ end
data/lib/monotonic.rb ADDED
@@ -0,0 +1 @@
1
+ require_relative './Monotonic/Timer'
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monotonic.rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - thoran
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest-spec-context
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Create accurate timings of excution in Ruby.
42
+ email: code@thoran.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/Monotonic/Time.rb
48
+ - lib/Monotonic/Timer.rb
49
+ - lib/Monotonic/VERSION.rb
50
+ - lib/monotonic.rb
51
+ homepage: https://github.com/thoran/monotonic.rb
52
+ licenses:
53
+ - Ruby
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '2.5'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.2.3
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Monotonic timing made easy.
74
+ test_files: []