[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: make-hash-table :size
From: |
Oliver Scholz |
Subject: |
Re: make-hash-table :size |
Date: |
Sun, 29 Aug 2004 12:11:51 +0200 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3.50 (windows-nt) |
Pascal Bourguignon <spam@mouse-potato.com> writes:
> Kai Grossjohann <kai@emptydomain.de> writes:
>
>> Joost Kremers <joostkremers@yahoo.com> writes:
>>
>> > i'm writing a program in emacs that makes rather extensive use of small
>> > hash tables, about a dozen elemens or so. i'm going over my code again, to
>> > see if i can improve things here and there, and i suddenly realise that
>> > MAKE-HASH-TABLE takes a :size argument.
>>
>> I wonder if hash tables are really faster than alists in this case.
>> Have you tried both?
>
> Well, it seems that yes, non-empty emacs hash tables are faster than
> alists...
[...]
For about a dozen elements? I doubt that. I would assume that the
small overhead in hash key access is likely to make alists more
efficient for such few elements. And indeed, profiling supports that
assumption:
(defconst test-alist
(let ((lst (make-list 14 '(lirum . larum))))
(append lst '((alpha . beta)))))
(defconst test-hash
(let ((hash (make-hash-table :size 15 :test 'eq)))
(puthash 'alpha 'beta hash)
hash))
(defun test-hash-access ()
(gethash 'alpha test-hash))
(defun test-alist-access ()
(cdr (assq 'alpha test-alist)))
(defun test-run ()
(interactive)
(dolist (func '(test-hash-access test-alist-access))
(unless (byte-code-function-p
(symbol-function func))
(byte-compile func)))
(elp-instrument-function 'test-hash-access)
(elp-instrument-function 'test-alist-access)
(dotimes (ignore-me 10000)
(test-hash-access)
(test-alist-access))
(elp-results))
On my Emacs 21.3 on a 1.5 GHtz Athlon M-x test-run gives:
Function Name Call Count Elapsed Time Average Time
================= ========== ============ ============
test-hash-access 10000 0.09 9e-006
test-alist-access 10000 0.04 4e-006
Oliver
--
13 Fructidor an 212 de la Révolution
Liberté, Egalité, Fraternité!
- make-hash-table :size, Joost Kremers, 2004/08/23
- Re: make-hash-table :size, Stefan Monnier, 2004/08/23
- Re: make-hash-table :size, Kai Grossjohann, 2004/08/28
- Message not available
- Re: make-hash-table :size, Pascal Bourguignon, 2004/08/28
- Re: make-hash-table :size,
Oliver Scholz <=
- Re: make-hash-table :size, Pascal Bourguignon, 2004/08/29
- Re: make-hash-table :size, Oliver Scholz, 2004/08/29
- Re: make-hash-table :size, Oliver Scholz, 2004/08/29
- Re: make-hash-table :size, Oliver Scholz, 2004/08/29
- Re: make-hash-table :size, Pascal Bourguignon, 2004/08/29