auctex-devel
[Top][All Lists]
Advanced

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

Re: GNU AUCTeX branch, master, updated. 34befcc17649fd6615fd4ef8756fb787


From: Arash Esbati
Subject: Re: GNU AUCTeX branch, master, updated. 34befcc17649fd6615fd4ef8756fb78705f7fe55
Date: Wed, 23 Feb 2022 14:41:16 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50

Tassilo Horn <tsdh@gnu.org> writes:

> And in fact, `benchmark' suggest appending those two concrete lists is
> faster than building a 2-element list containing the values of both
> variables which makes sense:
>
> (benchmark 1000000
>            '(list LaTeX-math-list LaTeX-math-default))
> "Elapsed time: 0.607044s (0.490079s in 6 GCs)"
>
> (benchmark 1000000
>            '(append LaTeX-math-list LaTeX-math-default))
> "Elapsed time: 0.170943s"

This was more or less my not tested assumption as I wrote my first mail.

> So how can the original benchmarking result be true?
>
> Well, the answer is that I've benchmarked a compiled vs. an interpreted
> function.

And it didn't occur to me as well as I did the same exercise here :-[

> After evaluating
>
>   (byte-compile 'LaTeX--completion-annotation-from-math-menu-with-append)
>
> the runtimes of the benchmarks are about the same with slight advantages
> for the version using `append'.  I guess as soon as `LaTeX-math-list'
> has two or more items, it'll tip over to the double-dolist variant.

I made a test case like this:

--8<---------------cut here---------------start------------->8---
(setq LaTeX-math-list nil)
(setq LaTeX-math-list
      '((?8 "infty" "Misc Symbol" 8734)
        (?8 "infty" "Misc Symbol" 8734)
        (?8 "infty" "Misc Symbol" 8734)
        (?8 "infty" "Misc Symbol" 8734)
        (?8 "infty" "Misc Symbol" 8734)
        (?8 "infty" "Misc Symbol" 8734)
        (?8 "infty" "Misc Symbol" 8734)
        (?8 "infty" "Misc Symbol" 8734)
        (?8 "infty" "Misc Symbol" 8734)
        (?8 "infty" "Misc Symbol" 8734)))

;; Current implementation, only renamed:
(defun LaTeX--completion-annotation-from-math-menu-with-list (sym)
  "Return a completion annotation for a SYM.
The annotation is usually a unicode representation of the macro
SYM's compiled representation, e.g., if SYM is alpha, α is
returned."
  (catch 'found
    (dolist (var (list LaTeX-math-list LaTeX-math-default))
      (dolist (e var)
        (let ((val (cadr e)))
          (when (and (stringp val)
                     (string= val sym))
            (let ((char (nth 3 e)))
              (when char
                (throw 'found
                       (concat " " (char-to-string char)))))))))))

(defun LaTeX--completion-annotation-from-math-menu-with-append (sym)
  "Return a completion annotation for a SYM.
The annotation is usually a unicode representation of the macro
SYM's compiled representation, e.g., if SYM is alpha, α is
returned."
  (catch 'found
    (dolist (e (append LaTeX-math-list LaTeX-math-default))
      (when (string= (cadr e) sym)
        (let ((char (nth 3 e)))
          (when char
            (throw 'found
                   (concat " " (char-to-string char)))))))))

(byte-compile 'LaTeX--completion-annotation-from-math-menu-with-list)
(byte-compile 'LaTeX--completion-annotation-from-math-menu-with-append)

(benchmark 10000
           '(LaTeX--completion-annotation-from-math-menu-with-list "aleph"))
(benchmark 10000
           '(LaTeX--completion-annotation-from-math-menu-with-append "aleph"))
--8<---------------cut here---------------end--------------->8---

The results are:

========================================================================
closure   LaTeX-math-list 
--------  --------------------------------------------------------------
          nil                             10 elements
          ------------------------------- ------------------------------
list      1.567220s (0.870875s in 11 GCs) 1.675717s (0.945968s in 12 GCs)
append    0.905904s (0.473733s in 6 GCs)  0.956845s (0.471727s in 6 GCs)
========================================================================

=====================================
Compiled  LaTeX-math-list 
--------  ---------------------------
          nil             10 elements
          --------------- -----------
list      0.091425s       0.105919s
append    0.066096s       0.094899s
=====================================

For the non-compiled ones, the implementation with `list' is slower and
suffers a little more from `LaTeX-math-list' with 10 elements.

For the compiled ones, the implementation with `list' is again slower
but suffers less from `LaTeX-math-list' with 10 elements.  The picture
looks completely different with 12 or more elements in
`LaTeX-math-list'.

So the current implementation is good for users with lot of additions to
`LaTeX-math-list', casual nil-users like me will loose :-)

Nice exercise, BTW.  Best, Arash



reply via email to

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