monotonic.rb 0.7.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf995a6ab7105dc05b1b11b660fc4a28b34f07d784c5c13af2b83e46c1d5b949
4
- data.tar.gz: 871dc0fc14b0771d4ddc00d7717787df34ace4d98b248e8613ba24918c40e641
3
+ metadata.gz: 1ed52df8a021bca41cae021d5b11408c8bd6b0fc80025a46a56b688cafa4fcdc
4
+ data.tar.gz: c45841b92c1da76259799f4c6c55ba9a540b9b25464acd82560f30a2c10e9234
5
5
  SHA512:
6
- metadata.gz: 809325b41986a73bea427d0685a4b63f42a6a89a090716edda20e400c5f9a0b91ec8ba28e1844ef63470cdef8368b913f3479488e449076abd2f63321c9aaa42
7
- data.tar.gz: 744d49e5aaa3028ac0fbf9180e146dd73ceb5c2ea6da50fcb33e72ef5659586aacff6786be1526244ab195f6e144a9b8a75b6fe488ed7a1cbd398e273eaa9ae2
6
+ metadata.gz: 4cf743fb3e9303efe1439f0532462045525b1439523bce53cfc96f293df4da5d33a94676e1b71e995cb908b29cb8295470111dc7857d6712e569ca348a45f6f6
7
+ data.tar.gz: 739e6a9032050231fdc5f761a6581a70aded2512981f7cf9e34e6774a43215e87db9d3911c6aec214269ac1a08282ef5933920e2121ab11119f6b0c34f5ef0a1
data/CHANGELOG CHANGED
@@ -1,5 +1,19 @@
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
+
3
17
  ## 20260812
4
18
 
5
19
  0.7.2: + gemspec 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
 
@@ -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
- @boot_time + seconds_since_boot
81
+ Sys::Uptime.boot_time + seconds_since_boot
71
82
  end
72
83
  end
73
84
  end
@@ -2,5 +2,5 @@
2
2
  # Monotonic::VERSION
3
3
 
4
4
  module Monotonic
5
- VERSION = '0.7.2'
5
+ VERSION = '0.7.3'
6
6
  end
data/lib/monotonic.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # monotonic.rb
2
2
  # Monotonic
3
3
 
4
+ require_relative './Monotonic/Time'
4
5
  require_relative './Monotonic/Timer'
5
6
  require_relative './Monotonic/VERSION'
@@ -7,9 +7,8 @@ describe Monotonic::Time do
7
7
  subject{Monotonic::Time.now}
8
8
 
9
9
  describe "#initialize" do
10
- it "the time spent in the block is returned as the value of the block" do
11
- expect(subject.instance_variable_get(:@boot_time)) \
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,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.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -84,6 +84,7 @@ files:
84
84
  - test/Monotonic/Timer_test.rb
85
85
  - test/Monotonic/VERSION_test.rb
86
86
  - test/gemspec_test.rb
87
+ - test/loading_test.rb
87
88
  homepage: https://github.com/thoran/monotonic.rb
88
89
  licenses:
89
90
  - MIT