Subject: Re: bug#11935: XINT etc. should be functions

From: Paul Eggert <[email-masked]>
Date: Sun, 15 Jul 2012 06:41:41 -0700

On 07/13/2012 07:20 PM, Richard Stallman wrote:
> How does this change affect performance with -O0?

It hurts it.  In normal operation I don't notice --
everything is plenty fast enough -- but in an artificial
benchmark designed to stress the new code (see below) the
performance is significantly worse.  If this is an issue,
we can mark these new functions with __attribute__
((__always_inline__)), but I'm inclined to try things
without this attribute, and resort to the attribute only if
needed.

I did two measures of performance.  "text" simply counts the
number of bytes in the text segment.  "bench" counts the
number of CPU seconds consumed by running the benchmark
described below.  "current" refers to trunk bzr 109093, and
"patched" to that bzr after the proposed patch is applied.
In both cases I've normalized the numbers to the current
default (so it scores as 1), and smaller numbers are better.

text   bench
1.000   1.00   current (default optimization)
0.995   0.99   patched (default optimization)
1.332   1.82   current (-O0)
1.410  11.86   patched (-O0)

My benchmark was (benchmark 100000), with the following
code, byte-compiled.  My platform is Fedora 15 x86-64,
compiled with GCC 4.7.1.  Benchmark timings are sloppy, as
usual, so I wouldn't attach much significance past the first
couple of digits.

(defvar longlist '(a b c d e f g h i j k l m n o p q r s t u v w x y z))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(defvar x)

(defun benchmark-with (n)
  (let ((start (float-time (get-internal-run-time)))
	(v (make-vector 1 0))
	(i 0))
    (while (< i n)
      (setq x (nth 8000 longlist))
      (setq i (1+ i)))
    (- (float-time (get-internal-run-time)) start)))

(defun benchmark-without (n)
  (let ((start (float-time (get-internal-run-time)))
	(v (make-vector 1 0))
	(i 0))
    (while (< i n)
      (setq i (1+ i)))
    (- (float-time (get-internal-run-time)) start)))

(defun benchmark (n)
  (- (benchmark-with n)
     (benchmark-without n)))