feat: small performance improvement for converting time (#1342) · python-zeroconf/python-zeroconf@73d3ab9

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -1,4 +1,4 @@

11
22

cpdef double current_time_millis()

33
4-

cpdef millis_to_seconds(object millis)

4+

cpdef millis_to_seconds(double millis)

Original file line numberDiff line numberDiff line change

@@ -26,15 +26,17 @@

2626

_float = float

2727
2828
29-

def current_time_millis() -> float:

29+

def current_time_millis() -> _float:

3030

"""Current time in milliseconds.

3131
3232

The current implemention uses `time.monotonic`

3333

but may change in the future.

34+
35+

The design requires the time to match asyncio.loop.time()

3436

"""

3537

return time.monotonic() * 1000

3638
3739
38-

def millis_to_seconds(millis: _float) -> float:

40+

def millis_to_seconds(millis: _float) -> _float:

3941

"""Convert milliseconds to seconds."""

4042

return millis / 1000.0