monotonic.rb 0.7.1 → 0.7.3
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 +4 -4
- data/CHANGELOG +22 -0
- data/README.md +2 -0
- data/lib/Monotonic/Time.rb +13 -2
- data/lib/Monotonic/VERSION.rb +1 -1
- data/lib/monotonic.rb +1 -0
- data/test/Monotonic/Time_test.rb +6 -3
- data/test/gemspec_test.rb +28 -0
- data/test/loading_test.rb +23 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1ed52df8a021bca41cae021d5b11408c8bd6b0fc80025a46a56b688cafa4fcdc
|
|
4
|
+
data.tar.gz: c45841b92c1da76259799f4c6c55ba9a540b9b25464acd82560f30a2c10e9234
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4cf743fb3e9303efe1439f0532462045525b1439523bce53cfc96f293df4da5d33a94676e1b71e995cb908b29cb8295470111dc7857d6712e569ca348a45f6f6
|
|
7
|
+
data.tar.gz: 739e6a9032050231fdc5f761a6581a70aded2512981f7cf9e34e6774a43215e87db9d3911c6aec214269ac1a08282ef5933920e2121ab11119f6b0c34f5ef0a1
|
data/CHANGELOG
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 20260816
|
|
4
|
+
|
|
5
|
+
0.7.3: Require Monotonic::Time from the gem, and stop every instant fetching the boot time.
|
|
6
|
+
|
|
7
|
+
1. ~ lib/monotonic.rb: + require_relative Monotonic/Time. It had reached a caller only by way of lib/Monotonic/Timer.rb requiring a file which Timer stopped using at 0.7.0, when the two took different clocks. Delete that stray line and Monotonic::Time would have vanished from the published gem, and nothing said so.
|
|
8
|
+
2. ~ lib/Monotonic/Timer.rb: - require_relative ./Time, which nothing there has wanted since 0.7.0.
|
|
9
|
+
3. + test/loading_test.rb: that requiring the gem defines Monotonic::Time and Monotonic::Timer, and the version. In a process of its own, this one having loaded every file directly and so being unable to tell what the gem alone would bring. The same hole as VERSION.rb before 0.7.1: a file nothing names is a file nothing checks.
|
|
10
|
+
4. ~ Monotonic::Time#to_time: asks Sys::Uptime for the boot time rather than every instant keeping one. Only this method wanted it, and asking cost 1740ns of the 1947ns an instant took to make, so an instant now costs 194ns. Memoising it was tried and is wrong: Darwin computes kern.boottime from the wall clock and the uptime, so it moves as the clock is disciplined, and a kept copy would fix the origin while the mapping drifted from it.
|
|
11
|
+
5. ~ test/Monotonic/Time_test.rb: the #initialize test asserted @boot_time was set, under a description copied from Timer's about blocks. It now asserts that an instant keeps the reading and nothing else. + that #to_time lands upon the wall clock, which nothing checked.
|
|
12
|
+
6. ~ README.md: what Monotonic::Time is for, since 0.7.0 left it with no caller in the library and said only that Timer had stopped using it. It is the point type: the difference of two instants is what a monotonic clock is read for, and #to_time places one against the wall clock.
|
|
13
|
+
7. + .gitignore: the standard list, as duration.rb and namo carry verbatim, in place of the three lines here. It is not among spec.files, so nothing in the published gem changes by it.
|
|
14
|
+
8. ~ Monotonic::VERSION: /0.7.2/0.7.3/
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## 20260812
|
|
18
|
+
|
|
19
|
+
0.7.2: + gemspec test.
|
|
20
|
+
|
|
21
|
+
1. + test/gemspec_test.rb: Ensure that the specification validates, that no date is pinned, that the version comes from Monotonic::VERSION, and that the runtime and development dependencies are those expected.
|
|
22
|
+
2. ~ Monotonic::VERSION: /0.7.1/0.7.2/
|
|
23
|
+
|
|
24
|
+
|
|
3
25
|
## 20260812
|
|
4
26
|
|
|
5
27
|
0.7.1: + VERSION test.
|
data/README.md
CHANGED
|
@@ -22,6 +22,8 @@ How finely a clock advances is the platform's business and not this library's to
|
|
|
22
22
|
|
|
23
23
|
A reading is denominated in nanoseconds whether or not the clock affords them, so that is the method which says what a reading is worth. Two figures give the sense of it upon the finer clock: reading it costs about 34ns against the 42ns it takes to advance, the two being close enough that there is little to be had by going finer, and a pair of `Float`s would not begin to lose it until some six years of uptime — but they would begin.
|
|
24
24
|
|
|
25
|
+
What `Monotonic::Time` is for follows from that. It is the point type: `Monotonic::Timer` used it as its own substrate until 0.7.0, when the two took different clocks, and what remains to it is what a point is good for — the difference of two instants, which is the reason a monotonic clock is read at all, and `#to_time`, which places one against the wall clock by way of the boot time.
|
|
26
|
+
|
|
25
27
|
|
|
26
28
|
## Installation
|
|
27
29
|
|
data/lib/Monotonic/Time.rb
CHANGED
|
@@ -25,6 +25,13 @@ module Monotonic
|
|
|
25
25
|
self.new
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
# Invariant for the life of the process, coming from kern.boottime, which
|
|
29
|
+
# does not move. It was asked afresh upon every instance and cost 1740ns
|
|
30
|
+
# of the 1947ns an instant took to make.
|
|
31
|
+
def boot_time
|
|
32
|
+
@boot_time ||= Sys::Uptime.boot_time
|
|
33
|
+
end
|
|
34
|
+
|
|
28
35
|
# How finely this clock advances, in nanoseconds. It is asked rather than
|
|
29
36
|
# tabulated, being a property of the processor and the operating system
|
|
30
37
|
# and not of this library: upon macOS CLOCK_MONOTONIC answers 1000 here.
|
|
@@ -50,7 +57,6 @@ module Monotonic
|
|
|
50
57
|
end
|
|
51
58
|
|
|
52
59
|
def initialize
|
|
53
|
-
@boot_time = Sys::Uptime.boot_time
|
|
54
60
|
@nanoseconds_since_boot = Process.clock_gettime(CLOCK, :nanosecond)
|
|
55
61
|
end
|
|
56
62
|
|
|
@@ -66,8 +72,13 @@ module Monotonic
|
|
|
66
72
|
"#{seconds_since_boot} seconds since boot."
|
|
67
73
|
end
|
|
68
74
|
|
|
75
|
+
# The boot time is asked for here rather than kept upon every instant. It
|
|
76
|
+
# cost 1740ns of the 1947ns an instant took to make, and only this method
|
|
77
|
+
# wants it — so an instant is now cheap to take, and the mapping still
|
|
78
|
+
# uses the boot time as it stands rather than as it stood, Darwin moving
|
|
79
|
+
# kern.boottime as the wall clock is disciplined.
|
|
69
80
|
def to_time
|
|
70
|
-
|
|
81
|
+
Sys::Uptime.boot_time + seconds_since_boot
|
|
71
82
|
end
|
|
72
83
|
end
|
|
73
84
|
end
|
data/lib/Monotonic/VERSION.rb
CHANGED
data/lib/monotonic.rb
CHANGED
data/test/Monotonic/Time_test.rb
CHANGED
|
@@ -7,9 +7,8 @@ describe Monotonic::Time do
|
|
|
7
7
|
subject{Monotonic::Time.now}
|
|
8
8
|
|
|
9
9
|
describe "#initialize" do
|
|
10
|
-
it "the
|
|
11
|
-
expect(subject.
|
|
12
|
-
.must_equal(Sys::Uptime.boot_time)
|
|
10
|
+
it "keeps the reading and nothing else, the boot time being wanted only by #to_time" do
|
|
11
|
+
expect(subject.instance_variables).must_equal([:@nanoseconds_since_boot])
|
|
13
12
|
end
|
|
14
13
|
|
|
15
14
|
it "the reading is taken from the monotonic clock in nanoseconds" do
|
|
@@ -77,5 +76,9 @@ describe Monotonic::Time do
|
|
|
77
76
|
it "returns an instance of time" do
|
|
78
77
|
expect(subject.to_time.class).must_equal(Time)
|
|
79
78
|
end
|
|
79
|
+
|
|
80
|
+
it "lands upon the wall clock, the boot time being asked for as it stands" do
|
|
81
|
+
expect((subject.to_time - Time.now).abs).must_be :<, 0.01
|
|
82
|
+
end
|
|
80
83
|
end
|
|
81
84
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require_relative '../lib/monotonic.rb'
|
|
2
|
+
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
require 'minitest-spec-context'
|
|
5
|
+
|
|
6
|
+
describe 'monotonic.rb.gemspec' do
|
|
7
|
+
let(:spec){Gem::Specification.load(File.expand_path('../monotonic.rb.gemspec', __dir__))}
|
|
8
|
+
|
|
9
|
+
it "is a valid specification" do
|
|
10
|
+
_(spec.validate).must_equal(true)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "does not pin a date" do
|
|
14
|
+
_(spec.date).must_equal(Gem::Specification.new.date)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "takes its version from Monotonic::VERSION" do
|
|
18
|
+
_(spec.version.to_s).must_equal(Monotonic::VERSION)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "declares its runtime dependencies" do
|
|
22
|
+
_(spec.runtime_dependencies.map(&:name).sort).must_equal(%w{sys-uptime})
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "declares its development dependencies" do
|
|
26
|
+
_(spec.development_dependencies.map(&:name).sort).must_equal(%w{minitest minitest-spec-context rake})
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require_relative '../lib/monotonic.rb'
|
|
2
|
+
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
require 'minitest-spec-context'
|
|
5
|
+
|
|
6
|
+
# In its own process, since this one has loaded every file directly and so could
|
|
7
|
+
# not tell what requiring the gem alone would bring.
|
|
8
|
+
describe 'loading' do
|
|
9
|
+
def ruby(source)
|
|
10
|
+
lib = File.expand_path('../lib', __dir__)
|
|
11
|
+
IO.popen(['ruby', "-I#{lib}", '-e', source], err: [:child, :out]){|io| io.read}.strip
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "defines both classes upon requiring the gem" do
|
|
15
|
+
expect(ruby('require "monotonic.rb"; print [defined?(Monotonic::Time), defined?(Monotonic::Timer)].inspect')) \
|
|
16
|
+
.must_equal('["constant", "constant"]')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "defines the version too" do
|
|
20
|
+
expect(ruby('require "monotonic.rb"; print Monotonic::VERSION')) \
|
|
21
|
+
.must_equal(Monotonic::VERSION)
|
|
22
|
+
end
|
|
23
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: monotonic.rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
@@ -83,6 +83,8 @@ files:
|
|
|
83
83
|
- test/Monotonic/Time_test.rb
|
|
84
84
|
- test/Monotonic/Timer_test.rb
|
|
85
85
|
- test/Monotonic/VERSION_test.rb
|
|
86
|
+
- test/gemspec_test.rb
|
|
87
|
+
- test/loading_test.rb
|
|
86
88
|
homepage: https://github.com/thoran/monotonic.rb
|
|
87
89
|
licenses:
|
|
88
90
|
- MIT
|