unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: "Mattias Engdegård" <mattiase@acm.org>
Cc: 44674@debbugs.gnu.org, Philipp Stephani <p.stephani2@gmail.com>
Subject: bug#44674: 28.0.50; Adding current-cpu-time for performance tests
Date: Mon, 16 Nov 2020 10:27:29 -0500	[thread overview]
Message-ID: <jwvzh3hjpu3.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <C161C9BA-8FCE-4845-A67E-6A6A1871CB3D@acm.org> ("Mattias Engdegård"'s message of "Mon, 16 Nov 2020 11:11:34 +0100")

Philipp wrote:
> It might be beneficial to use the higher-resolution clock_gettime with
> CLOCK_PROCESS_CPUTIME_ID if available and only fall back to clock()
> otherwise.
>
> While there, consider also implementing a function to read the
> CLOCK_MONOTONIC clock – that should be preferred over the realtime
> clock for stopwatch-style measurements.

Given that we've lived without any of it for so many years, I'm not sure
it's worth the trouble.  Also since I'm not familiar with any of those
interfaces, I'd welcome it if someone else could do that if
they're interested.

Eli said:
> AFAIU, using 'clock' here is not the best idea, as there are caveats wrt to
> calling 'system', and the origin of the returned value is not well defined
> to be portable.

What do you mean by "origin" and by "calling 'system'"?

Mattias added:
>> +The return value is a pair (CPU-TICKS . TICKS-PER-SEC).
> Perhaps not ideal to cons in a timing primitive where low overhead is
> called for.

I expect that the time it takes to perform the `funcall` to get to this
function is itself larger than the time it takes to run `Fcons`, so I'm
not too worried about this overhead.

> What about just returning an integer and have a different way to get
> at TICKS-PER-SEC?

I designed it this way to keep the change as simple as possible, but
yes, we could have two separate functions.

> Ideally the returned value should be a fixnum to minimise overhead, but it
> may restrict the range on 32-bit platforms.

`make_int` will return a fixnum when possible.  Are you suggesting we
modulo-truncate the integer so it fits i a fixnum?  I think that on
32bit platforms this will lose too much range (I guess we could divide
instead of modulo-truncate, and lose precision instead, tho).  Not sure
it's worth the trouble, tho.

In my experience measuring CPU or wall clock time for things like
benchmarks is only meaningful if it's a non-trivial amount of time (like
0.1s or more), so the added cost of Fcons or allocating a bignum
is negligible.


        Stefan






  parent reply	other threads:[~2020-11-16 15:27 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-16  1:07 bug#44674: 28.0.50; Adding current-cpu-time for performance tests Stefan Monnier
2020-11-16  7:13 ` Philipp Stephani
2020-11-16  7:58 ` Eli Zaretskii
2020-11-16  8:18   ` Eli Zaretskii
2020-11-16 11:46     ` Philipp Stephani
2020-11-16 17:17       ` Eli Zaretskii
2020-11-16 18:31         ` Philipp Stephani
2020-11-16 19:12           ` Eli Zaretskii
2020-11-16 22:09           ` Lars Ingebrigtsen
2020-11-16 10:11 ` Mattias Engdegård
2020-11-16 10:40   ` Eli Zaretskii
2020-11-16 10:48     ` Philipp Stephani
2020-11-16 10:53     ` Mattias Engdegård
2020-11-16 17:15       ` Eli Zaretskii
2020-11-16 15:27   ` Stefan Monnier [this message]
2020-11-16 16:14     ` Mattias Engdegård
2020-11-16 17:28     ` Eli Zaretskii
2020-11-16 17:38       ` Eli Zaretskii
2020-11-16 17:59         ` Andreas Schwab
2020-11-16 18:27           ` Eli Zaretskii
2020-11-16 18:41         ` Stefan Monnier
2020-11-16 19:22           ` Eli Zaretskii
2020-11-16 18:32       ` Philipp Stephani
2020-11-16 19:17         ` Eli Zaretskii
2020-11-16 20:10         ` Stefan Monnier
2020-11-16 18:41       ` Stefan Monnier
2020-11-16 18:39     ` Philipp Stephani
2020-11-16 19:07       ` Stefan Monnier
2020-11-16 17:13   ` Eli Zaretskii
2020-11-16 19:15     ` Mattias Engdegård
2022-04-26 13:55 ` Lars Ingebrigtsen
2022-04-26 15:13   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-27 13:09     ` Lars Ingebrigtsen
2022-04-27 17:14       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-27 17:20         ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvzh3hjpu3.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=44674@debbugs.gnu.org \
    --cc=mattiase@acm.org \
    --cc=p.stephani2@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).