[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
remove-duplicates performances
From: |
Thierry Volpiatto |
Subject: |
remove-duplicates performances |
Date: |
Fri, 20 May 2011 15:51:02 +0200 |
User-agent: |
Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (gnu/linux) |
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