From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nicolas Richard Newsgroups: gmane.emacs.devel Subject: Re: Would seq-range and seq-mapcat be useful? Date: Fri, 30 Jan 2015 17:36:43 +0100 Message-ID: <54CBB31B.8040309@yahoo.fr> References: <878uglwmra.fsf@petton.fr> <874mr9w8at.fsf@petton.fr> <87lhkkefhn.fsf@petton.fr> <87wq448djj.fsf@yahoo.fr> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1422635818 9660 80.91.229.3 (30 Jan 2015 16:36:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 30 Jan 2015 16:36:58 +0000 (UTC) Cc: Nicolas Petton , Stefan Monnier , emacs-devel To: Oleh Krehel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 30 17:36:57 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YHEYz-0006sD-F2 for ged-emacs-devel@m.gmane.org; Fri, 30 Jan 2015 17:36:57 +0100 Original-Received: from localhost ([::1]:37630 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHEYy-0007uA-VO for ged-emacs-devel@m.gmane.org; Fri, 30 Jan 2015 11:36:56 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49972) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHEYd-0007u1-QP for emacs-devel@gnu.org; Fri, 30 Jan 2015 11:36:36 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YHEYY-0007YD-Ri for emacs-devel@gnu.org; Fri, 30 Jan 2015 11:36:35 -0500 Original-Received: from mxin.ulb.ac.be ([164.15.128.112]:57691) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHEYY-0007Xs-Mj for emacs-devel@gnu.org; Fri, 30 Jan 2015 11:36:30 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As4BAAiyy1SkD4Xx/2dsb2JhbAANTYcyryIBAQEBAQEGlWGCTwKBYAEBAQEBhQoBAQQjDwFFARALDgwCBRYLAgIJAwIBAgFFBg0BBwEBiBMBwFpwgWuNWwGGKQEBAQEBAQEDAQEBAQEBAQEagSGEY4Iqh0oHgmiBQQEEmB6GKYwogiMdgVGDMAEBAQ Original-Received: from mathsrv4.ulb.ac.be (HELO [172.19.79.241]) ([164.15.133.241]) by smtp.ulb.ac.be with ESMTP; 30 Jan 2015 17:36:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: X-TagToolbar-Keys: D20150130173643883 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 164.15.128.112 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:182077 Archived-At: Le 30/01/2015 17:04, Oleh Krehel a écrit : > Mine's faster: I think it will depend on the number of keys. (defmacro util-timeit (&rest expr) `(progn (garbage-collect) ;; avoid gc later. maybe. (let ((t-beg (float-time)) (res (dotimes (i 500) ;; I reduced this a bit because I have a slow system. ,@expr)) (t-end (float-time))) (/ (- t-end t-beg) 500)))) (progn ;; use M-x compile-defun to eval this part (defun yf/seq-group-by (fn lst) (let ((hash (make-hash-table :test 'equal))) (dolist (elm lst) (push elm (gethash (funcall fn elm) hash))) hash)) (defun seq-group-by (fn lst) (nreverse (cl-reduce (lambda (acc it) (let* ((key (funcall fn it)) (cell (assoc key acc))) (if cell (setcdr cell (push it (cdr cell))) (push (list key it) acc)) acc)) lst :initial-value nil)))) (defun make-random-list (n) (let ((tmp)) (dotimes (_ n) (push (cons (random 150) t) tmp)) ;; I guess only the keys matter tmp)) (let ((tmp (make-random-list 10))) (list (util-timeit (yf/seq-group-by #'car tmp)) (util-timeit (seq-group-by #'car tmp)))) (3.778600692749023e-05 3.6581039428710935e-05) (let ((tmp (make-random-list 100))) (list (util-timeit (yf/seq-group-by #'car tmp)) (util-timeit (seq-group-by #'car tmp)))) (0.0002734408378601074 0.0005863599777221679) (let ((tmp (make-random-list 1000))) (list (util-timeit (yf/seq-group-by #'car tmp)) (util-timeit (seq-group-by #'car tmp)))) (0.00434891939163208 0.010494112968444824) I wasn't really trying to compete though, just giving another point of view. -- Nico.