From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.devel Subject: remove-duplicates performances Date: Fri, 20 May 2011 15:51:02 +0200 Message-ID: <877h9lv5tl.fsf@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1305899486 26617 80.91.229.12 (20 May 2011 13:51:26 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 20 May 2011 13:51:26 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri May 20 15:51:22 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QNQ6s-00011T-K8 for ged-emacs-devel@m.gmane.org; Fri, 20 May 2011 15:51:22 +0200 Original-Received: from localhost ([::1]:58384 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNQ6r-0006Ui-Ko for ged-emacs-devel@m.gmane.org; Fri, 20 May 2011 09:51:21 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:35525) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNQ6p-0006UT-L9 for emacs-devel@gnu.org; Fri, 20 May 2011 09:51:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QNQ6o-0008Mt-M7 for emacs-devel@gnu.org; Fri, 20 May 2011 09:51:19 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:59016) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNQ6n-0008Mm-Sg for emacs-devel@gnu.org; Fri, 20 May 2011 09:51:18 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QNQ6k-0000xO-4E for emacs-devel@gnu.org; Fri, 20 May 2011 15:51:14 +0200 Original-Received: from 65.77.197.77.rev.sfr.net ([77.197.77.65]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 20 May 2011 15:51:14 +0200 Original-Received: from thierry.volpiatto by 65.77.197.77.rev.sfr.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 20 May 2011 15:51:14 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 34 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 65.77.197.77.rev.sfr.net User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:BrAzwiKxg31WlErk8mDR75GcaAc= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:139546 Archived-At: 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