[Top][All Lists]

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

Re: Should `get-file-buffer' be implemented in Elisp?

From: tomas
Subject: Re: Should `get-file-buffer' be implemented in Elisp?
Date: Mon, 17 Jul 2023 07:06:02 +0200

On Sun, Jul 16, 2023 at 08:19:10PM +0000, Ihor Radchenko wrote:


> scenarios. And in general lookup as well as hash tables start to
> outperform alists just at 20-30 elements [1]

For me, it's more like 45-ish:

(let* ((size 50) ; alist, hash size
       (runs 10000) ; benchmark runs
       (alist '())
       (hash (make-hash-table :test 'eq :size 1549))
       (keys (make-vector size nil))
       (count size))
  ;; setup
  (while (> count 0)
    (setq count (1- count))
    (let ((sym (intern (format "SYM%04d%03d" (random 10000) count))))
      (aset keys count sym)
      (setq alist (cons (cons sym "foo") alist))
      (puthash sym "foo" hash)))
  ;; run
   (benchmark runs '(assq (aref keys (random size)) alist))
   (benchmark runs '(gethash (aref keys (random size)) hash))))

And even at 100, the absolute time is rather negligible. Somewhere
near 5000 buffers my (not very fast) machine reaches the 100ms
area for alists and lingers in the 2ms area for hashes (that would
be where I'd start worrying).

How many people around here have regularly 1000 buffers?

Those simple alists are surprisingly fast (I, too have often
the reflex to reach for hash tables, I know).


Attachment: signature.asc
Description: PGP signature

reply via email to

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