GNU bug report logs -
#71573
[PATCH] seconds-to-string-approximate
Previous Next
Reported by: JD Smith <jdtsmith <at> gmail.com>
Date: Sat, 15 Jun 2024 17:25:02 UTC
Severity: wishlist
Tags: patch
Merged with 71572
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
Message #19 received at 71573 <at> debbugs.gnu.org (full text, mbox):
On 6/22/24 05:55, Stefan Kangas wrote:
> Adam Porter <adam <at> alphapapa.net> writes:
>
>> ;; See also the built-in function `format-seconds', which I seem to have
>> ;; overlooked before writing this. However, a quick benchmark, run
>> ;; 100,000 times, shows that, when controllable formatting is not needed,
>> ;; `ts-human-format-duration' is much faster and generates less garbage:
>>
>> ;; | Form | x faster than next | Total runtime | #
>> of GCs | Total GC runtime |
>> ;;
>> |--------------------------+--------------------+---------------+----------+------------------|
>> ;; | ts-human-format-duration | 5.82 | 0.832945 |
>> 3 | 0.574929 |
>> ;; | format-seconds | slowest | 4.848253 |
>> 17 | 3.288799 |
>
> Is this used a lot in hot loops? IOW, is it worth optimizing?
It can be. Imagine formatting timestamps for thousands of items in a
vtable. And imagine that happening frequently, e.g. if the vtable is
redrawn automatically to account for data having arrived over the network.
> If yes, how about adding something like what you have as an optimization
> to `format-seconds` for when the format is very simple? Would that
> remove the need for `ts-human-format-duration'?
I don't know what form such an optimization would take. Perhaps someone
could profile it and optimize some hot spots in it, but I'll have to
decline that to-do for now, as my list is much too long already. :)
BTW, please note that I don't claim that ts-human-format-duration is
superior to format-seconds, because the latter is different and has some
additional features. Rather, ts-human-format-duration is an alternative
that can sometimes be worth using instead. I present it as food for
thought when considering to implement related functionality.
This bug report was last modified 205 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.