Skip to content

Commit 046f147

Browse files
Improve performance of System::Time.monotonic on Windows (#16555)
1 parent 7d6fc2a commit 046f147

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/crystal/system/win32/time.cr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ module Crystal::System::Time
5353
((filetime.dwHighDateTime.to_u64 << 32) | filetime.dwLowDateTime.to_u64).to_f64 / FILETIME_TICKS_PER_SECOND.to_f64
5454
end
5555

56-
private class_getter performance_frequency : Int64 do
56+
private def self.performance_frequency
5757
LibC.QueryPerformanceFrequency(out frequency)
5858
frequency
5959
end
6060

6161
def self.monotonic : {Int64, Int32}
6262
LibC.QueryPerformanceCounter(out ticks)
6363
frequency = performance_frequency
64-
{ticks // frequency, (ticks.remainder(frequency) * NANOSECONDS_PER_SECOND / frequency).to_i32}
64+
divmod = ticks.tdivmod(frequency)
65+
{divmod[0], (divmod[1] &* NANOSECONDS_PER_SECOND // frequency).to_i32!}
6566
end
6667

6768
def self.ticks : UInt64

0 commit comments

Comments
 (0)