all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* remove-duplicates performances
@ 2011-05-20 13:51 Thierry Volpiatto
  2011-05-20 14:09 ` Stefan Monnier
  2011-05-20 14:28 ` David Kastrup
  0 siblings, 2 replies; 14+ messages in thread
From: Thierry Volpiatto @ 2011-05-20 13:51 UTC (permalink / raw)
  To: emacs-devel

Hi all,
i just noticed that `remove-duplicates' is very slow.

Something like below seem much faster:

--8<---------------cut here---------------start------------->8---
(defun* remove-dups (seq &key (test 'eq))
  (let ((cont (make-hash-table :test test)))
    (loop for elm in seq
       unless (gethash elm cont)
       do (puthash elm elm cont)
       finally return (loop for i being the hash-values in cont collect i))))
--8<---------------cut here---------------end--------------->8---

Test:

(setq A (let ((seq (loop for i from 1 to 10000 collect i)))
          (append seq seq)))
(1 2 3 4 5 6 7 8 9 10 1 2 ...)

(remove-dups A)
(1 2 3 4 5 6 7 8 9 10 11 12 ...)
elp-results: remove-dups    1           0.013707      0.013707

(remove-duplicates A)
(1 2 3 4 5 6 7 8 9 10 11 12 ...)
elp-results: remove-duplicates  1           66.971619     66.971619

Would be nice to improve performances of `remove-duplicates'.

-- 
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 




^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2011-05-20 21:57 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-20 13:51 remove-duplicates performances Thierry Volpiatto
2011-05-20 14:09 ` Stefan Monnier
2011-05-20 14:39   ` Thierry Volpiatto
2011-05-20 16:14     ` Stefan Monnier
2011-05-20 17:46       ` Thierry Volpiatto
2011-05-20 15:16   ` Ted Zlatanov
2011-05-20 14:28 ` David Kastrup
2011-05-20 16:00   ` Thierry Volpiatto
2011-05-20 17:01     ` David Kastrup
2011-05-20 17:31       ` Thierry Volpiatto
2011-05-20 17:46         ` David Kastrup
2011-05-20 18:01           ` Stefan Monnier
2011-05-20 21:57             ` Pascal J. Bourguignon
2011-05-20 17:57       ` Ted Zlatanov

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.