all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>
Cc: pipcet@gmail.com, emacs-devel@gnu.org
Subject: Crashes in "C-h h"
Date: Wed, 3 Jul 2019 14:05:32 -0700	[thread overview]
Message-ID: <9b78b85d-a3c8-761f-e500-d51d4a985fa8@cs.ucla.edu> (raw)
In-Reply-To: <83muhvd9nm.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1160 bytes --]

>> As Eli's revised code suggests, if n is in fixnum range, then instead of
>> (FIXNUMP (x) && XFIXNUM (x) == n) it's typically a bit cleaner (and faster) to
>> write EQ (x, make_fixnum (n)).

> It normally shouldn't matter either way, but in that case the
> comparison is done in a loop, so the make_fixnum call can be done just
> once, outside the loop, which AFAIU makes the loop a tad faster.

Although it indeed doesn't matter normally, the EQ+make_fixnum version 
should be smaller and faster in typical use, even without hoisting the 
make_fixnum out of a loop. I just now ran the attached microbenchmark on 
a Xeon E5-2640 v2 with code compiled by GCC 9.1 x86-64, and got these 
results:

1031-lnxsrv09 $ time ./a.out 0 0   # no operation

real	0m28.150s
user	0m28.148s
sys	0m0.001s
1032-lnxsrv09 $ time ./a.out 0 0 0   # FIXNUMP+XFIXNUM

real	0m34.229s
user	0m34.227s
sys	0m0.001s
1033-lnxsrv09 $ time ./a.out 0 0 0 0    # EQ+make_fixnum

real	0m32.213s
user	0m32.211s
sys	0m0.001s

which indicates that the EQ+make_fixnum version was about 50% faster 
than the FIXNUMP+XFIXNUM version, once you subtract the overhead of the 
no-op benchmark control.

[-- Attachment #2: t.c --]
[-- Type: text/x-csrc, Size: 499 bytes --]

#include <config.h>
#include <lisp.h>

int
noop (Lisp_Object x, ptrdiff_t n)
{
  return 0;
}

int
f (Lisp_Object x, ptrdiff_t n)
{
  return FIXNUMP (x) && XFIXNUM (x) == n;
}

int
g (Lisp_Object x, ptrdiff_t n)
{
  return EQ (x, make_fixnum (n));
}

int
main (int argc, char **argv)
{
  int sum = 0;
  int (*p) (Lisp_Object, ptrdiff_t)
    = argc % 3 == 0 ? noop : argc % 3 == 1 ? f : g;
  for (long i = 0; i < 10000000000; i++)
    sum += p (i & 1 ? Qnil : make_fixnum (i), i);
  return sum & 1;
}

  reply	other threads:[~2019-07-03 21:05 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-01 14:38 Crashes in "C-h h" Eli Zaretskii
2019-07-01 14:44 ` Lars Ingebrigtsen
2019-07-01 14:57   ` Eli Zaretskii
2019-07-01 15:01 ` Andreas Schwab
2019-07-01 15:27   ` Eli Zaretskii
2019-07-01 15:40     ` Pip Cet
2019-07-01 15:51       ` Pip Cet
2019-07-02  2:31       ` Eli Zaretskii
2019-07-03  2:38       ` Paul Eggert
2019-07-03  4:28         ` Eli Zaretskii
2019-07-03 21:05           ` Paul Eggert [this message]
2019-07-04  2:34             ` Eli Zaretskii
2019-07-04  7:15               ` Paul Eggert
2019-07-04 13:05                 ` Eli Zaretskii
2019-07-04 20:58                   ` Pip Cet
2019-07-04 23:04                     ` Paul Eggert
2019-07-05  7:07                       ` Pip Cet
2019-07-05  7:52                         ` Eli Zaretskii
2019-07-05  8:17                           ` Pip Cet
2019-07-05  8:38                             ` Eli Zaretskii
2019-07-06  3:42                               ` Paul Eggert
2019-07-06  7:08                                 ` Eli Zaretskii
2019-07-06  9:12                                   ` VanL
2019-07-06 14:30                                     ` Paul Eggert
2019-07-11 13:10                                       ` [OffTopic] " VanL
2019-07-04  4:50             ` Pip Cet
2019-07-02  2:20     ` Eli Zaretskii
2019-07-01 15:06 ` Robert Pluim
2019-07-01 15:29   ` Eli Zaretskii
2019-07-01 15:47   ` Andreas Schwab
2019-07-02 14:34 ` Martin
2019-07-02 14:38   ` Eli Zaretskii

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

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

  git send-email \
    --in-reply-to=9b78b85d-a3c8-761f-e500-d51d4a985fa8@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=pipcet@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.