[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to canonicalize a time object

From: Stefan Monnier
Subject: Re: How to canonicalize a time object
Date: Sun, 14 Aug 2022 13:15:27 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Lars Ingebrigtsen [2022-08-14 17:41:45] wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> What's the best way in ELisp to turn an arbitrary time value into one
>> that will be as efficient as possible for `lisp_time_argument`?
> I'm not quite sure I understand the question -- the `t' type for
> `time-convert' is supposed to be the most efficient representation of an
> arbitrary time value,

Yes, it seems that using the representation returned by `time-convert`
when you ask for the `t` form is the "most efficient" for some
definition of it, but I'm specifically interested in the efficiency of
passing the result to `lisp_time_argument`: that function uses
`lisp_to_timespec` which has various "fast paths" and I'm not sure how
to make sure we'll go through them.  E.g. if we do (time-convert FLOAT t)
the returned value will be of the form (TICKS . 2^51) and for
(time-convert (HI LOW US) t) it'll be (TICKS . 10^6), but
`lisp_to_timespec` doesn't seem to have a fast path for 2^51 and I'm not
sure it has one for 10^6 (nor 10^12 used for (HI LOW US PS)).

It appears that the best choice currently is to use `timespec_hz`
(or 1 if the time is a whole number of seconds), but:

- There doesn't seem to be an easy way to get `timespec_hz` from ELisp.
- It's cumbersome to find out if a time value is a whole number
  of seconds.
- It's not very elegant to have ELisp code do such gymnastics which
  depend on the presence/absence of specific fast-paths in the C code,
  which my also change in the future.

> but if you don't have sub-second resolution to your time, the
> `integer' one is probably more efficient?

Indeed, tho only for that specific situation :-(

Of course, maybe we shouldn't care, and just presume that the slow path
which does a GMP mul+div is plenty fast anyway.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]