all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: emacs-devel@gnu.org
Subject: remove-duplicates performances
Date: Fri, 20 May 2011 15:51:02 +0200	[thread overview]
Message-ID: <877h9lv5tl.fsf@gmail.com> (raw)

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 




             reply	other threads:[~2011-05-20 13:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-20 13:51 Thierry Volpiatto [this message]
2011-05-20 14:09 ` remove-duplicates performances 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877h9lv5tl.fsf@gmail.com \
    --to=thierry.volpiatto@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.