Skip to content

Commit 5bf7b19

Browse files
Replace Time.monotonic with Time.instant (#16498)
1 parent e82b294 commit 5bf7b19

File tree

25 files changed

+72
-84
lines changed

25 files changed

+72
-84
lines changed

spec/std/crystal/event_loop/polling/poll_descriptor_spec.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Crystal::EventLoop::FakeLoop < Crystal::EventLoop::Polling
3131
operations << {:del, fd, closing}
3232
end
3333

34-
private def system_set_timer(time : Time::Span?) : Nil
34+
private def system_set_timer(time : Time::Instant?) : Nil
3535
end
3636
end
3737

spec/std/crystal/event_loop/timers_spec.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ require "crystal/event_loop/timers"
44
private struct Timer
55
include Crystal::PointerPairingHeap::Node
66

7-
property! wake_at : Time::Span
7+
property! wake_at : Time::Instant
88

99
def initialize(timeout : Time::Span? = nil)
10-
@wake_at = Time.monotonic + timeout if timeout
10+
@wake_at = Crystal::System::Time.instant + timeout if timeout
1111
end
1212

1313
def heap_compare(other : Pointer(self)) : Bool
@@ -89,7 +89,7 @@ describe Crystal::EventLoop::Timers do
8989
timers.add(pointerof(event2)).should be_false
9090
timers.add(pointerof(event3)).should be_false
9191

92-
event0.wake_at = -1.minute
92+
event0.wake_at = Crystal::System::Time.instant - 1.minute
9393
timers.add(pointerof(event0)).should be_true # added new head (next ready)
9494
end
9595

spec/std/http/spec_helper.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ private def wait_for(&)
1111
{% else %}
1212
5.seconds
1313
{% end %}
14-
now = Time.monotonic
14+
now = Time.instant
1515

1616
until yield
1717
Fiber.yield
1818

19-
if (Time.monotonic - now) > timeout
19+
if now.elapsed > timeout
2020
raise "server failed to start within #{timeout}"
2121
end
2222
end

spec/std/sync/spec_helper.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ require "wait_group"
33

44
module Sync
55
def self.eventually(timeout : Time::Span = 1.second, &)
6-
start = Time.monotonic
6+
start = Time.instant
77

88
loop do
99
Fiber.yield
1010

1111
begin
1212
yield
1313
rescue ex
14-
raise ex if (Time.monotonic - start) > timeout
14+
raise ex if start.elapsed > timeout
1515
else
1616
break
1717
end

spec/support/fibers.cr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
def wait_until_blocked(f : Fiber, timeout = 5.seconds)
2-
now = Time.monotonic
2+
now = Time.instant
33

44
until f.resumable?
55
Fiber.yield
6-
raise "Fiber failed to block within #{timeout}" if (Time.monotonic - now) > timeout
6+
raise "Fiber failed to block within #{timeout}" if now.elapsed > timeout
77
end
88
end
99

1010
def wait_until_finished(f : Fiber, timeout = 5.seconds)
11-
now = Time.monotonic
11+
now = Time.instant
1212
until f.dead?
1313
Fiber.yield
14-
raise "Fiber failed to finish within #{timeout}" if (Time.monotonic - now) > timeout
14+
raise "Fiber failed to finish within #{timeout}" if now.elapsed > timeout
1515
end
1616
end
1717

src/benchmark.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ module Benchmark
131131

132132
# Returns the time used to execute the given block.
133133
def measure(label = "", &) : BM::Tms
134-
t0, r0 = Process.times, Time.monotonic
134+
t0, r0 = Process.times, Time.instant
135135
yield
136-
t1, r1 = Process.times, Time.monotonic
136+
t1, r1 = Process.times, Time.instant
137137
BM::Tms.new(t1.utime - t0.utime,
138138
t1.stime - t0.stime,
139139
t1.cutime - t0.cutime,

src/benchmark/ips.cr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ module Benchmark
6767

6868
count = 0_u64
6969
elapsed = Time.measure do
70-
target = Time.monotonic + @warmup_time
70+
target = Time.instant + @warmup_time
7171

72-
while Time.monotonic < target
72+
while Time.instant < target
7373
item.call
7474
count += 1
7575
end
@@ -87,7 +87,7 @@ module Benchmark
8787
bytes = 0_i64
8888
cycles = 0_i64
8989

90-
target = Time.monotonic + @calculation_time
90+
target = Time.instant + @calculation_time
9191

9292
loop do
9393
elapsed = nil
@@ -97,7 +97,7 @@ module Benchmark
9797
bytes += bytes_taken
9898
cycles += item.cycles
9999
measurements << elapsed.not_nil!
100-
break if Time.monotonic >= target
100+
break if Time.instant >= target
101101
end
102102

103103
ips = measurements.map { |m| item.cycles.to_f / m.total_seconds }

src/compiler/crystal/macros/macros.cr

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Crystal::Program
8282
end
8383

8484
def macro_compile(filename)
85-
time = Time.monotonic
85+
time = Time.instant
8686

8787
source = File.read(filename)
8888

@@ -107,8 +107,7 @@ class Crystal::Program
107107
{% end %}
108108

109109
if can_reuse_previous_compilation?(filename, executable_path, recorded_requires_path, requires_path)
110-
elapsed_time = Time.monotonic - time
111-
return CompiledMacroRun.new(executable_path, elapsed_time, true)
110+
return CompiledMacroRun.new(executable_path, time.elapsed, true)
112111
end
113112

114113
result = host_compiler.compile Compiler::Source.new(filename, source), executable_path
@@ -131,8 +130,7 @@ class Crystal::Program
131130
requires_with_timestamps.to_json(file)
132131
end
133132

134-
elapsed_time = Time.monotonic - time
135-
CompiledMacroRun.new(executable_path, elapsed_time, false)
133+
CompiledMacroRun.new(executable_path, time.elapsed, false)
136134
end
137135

138136
@host_compiler : Compiler?

src/compiler/crystal/progress_tracker.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ module Crystal
1818
print_stats
1919
print_progress
2020

21-
time_start = Time.monotonic
21+
time_start = Time.instant
2222
retval = yield
23-
time_taken = Time.monotonic - time_start
23+
time_taken = time_start.elapsed
2424

2525
print_stats(time_taken)
2626
print_progress

src/crystal/event_loop/epoll.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Crystal::EventLoop::Epoll < Crystal::EventLoop::Polling
122122
@epoll.delete(fd) { yield }
123123
end
124124

125-
private def system_set_timer(time : Time::Span?) : Nil
125+
private def system_set_timer(time : Time::Instant?) : Nil
126126
if time
127127
@timerfd.set(time)
128128
else

0 commit comments

Comments
 (0)