Skip to content

Commit 23b756f

Browse files
committed
[GR-19220] Make Process.clock_gettime(Process::CLOCK_MONOTONIC) simpler (#2394)
PullRequest: truffleruby/2834
2 parents a2dc729 + 2da2a31 commit 23b756f

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/main/java/org/truffleruby/core/ProcessNodes.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public abstract class ProcessNodes {
2727
@Primitive(name = "process_time_nanotime")
2828
public abstract static class ProcessTimeNanoTimeNode extends PrimitiveArrayArgumentsNode {
2929

30-
@TruffleBoundary
3130
@Specialization
3231
protected long nanoTime() {
3332
return System.nanoTime();

src/main/ruby/truffleruby/core/process.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ def self.clock_gettime(id, unit=:float_second)
156156
end
157157

158158
case id
159+
when CLOCK_MONOTONIC # most common clock id
160+
time = Primitive.process_time_nanotime
159161
when CLOCK_REALTIME
160162
time = Primitive.process_time_instant
161-
when CLOCK_MONOTONIC
162-
time = Primitive.process_time_nanotime
163163
else
164164
time = Truffle::POSIX.truffleposix_clock_gettime(id)
165165
Errno.handle if time == 0
@@ -169,21 +169,21 @@ def self.clock_gettime(id, unit=:float_second)
169169
end
170170

171171
def self.nanoseconds_to_unit(nanoseconds, unit)
172-
case unit
172+
case unit # ordered by expected frequency
173+
when :float_second, nil
174+
nanoseconds / 1e9
173175
when :nanosecond
174176
nanoseconds
175177
when :microsecond
176178
nanoseconds / 1_000
177-
when :millisecond
178-
nanoseconds / 1_000_000
179-
when :second
180-
nanoseconds / 1_000_000_000
181179
when :float_microsecond
182180
nanoseconds / 1e3
183181
when :float_millisecond
184182
nanoseconds / 1e6
185-
when :float_second, nil
186-
nanoseconds / 1e9
183+
when :second
184+
nanoseconds / 1_000_000_000
185+
when :millisecond
186+
nanoseconds / 1_000_000
187187
else
188188
raise ArgumentError, "unexpected unit: #{unit}"
189189
end

0 commit comments

Comments
 (0)