From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Oleh Krehel Newsgroups: gmane.emacs.devel Subject: Re: Would seq-range and seq-mapcat be useful? Date: Fri, 30 Jan 2015 17:51:33 +0100 Message-ID: References: <878uglwmra.fsf@petton.fr> <874mr9w8at.fsf@petton.fr> <87lhkkefhn.fsf@petton.fr> <87wq448djj.fsf@yahoo.fr> <54CBB31B.8040309@yahoo.fr> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1422636708 25294 80.91.229.3 (30 Jan 2015 16:51:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 30 Jan 2015 16:51:48 +0000 (UTC) Cc: Nicolas Petton , Stefan Monnier , emacs-devel To: Nicolas Richard Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 30 17:51:47 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 1YHEnK-0005TQ-GO for ged-emacs-devel@m.gmane.org; Fri, 30 Jan 2015 17:51:46 +0100 Original-Received: from localhost ([::1]:37672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHEnJ-0004Oy-W8 for ged-emacs-devel@m.gmane.org; Fri, 30 Jan 2015 11:51:46 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHEnG-0004Oq-Td for emacs-devel@gnu.org; Fri, 30 Jan 2015 11:51:43 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YHEn8-00045M-Kj for emacs-devel@gnu.org; Fri, 30 Jan 2015 11:51:42 -0500 Original-Received: from mail-wg0-x233.google.com ([2a00:1450:400c:c00::233]:60593) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHEn8-00045E-E7 for emacs-devel@gnu.org; Fri, 30 Jan 2015 11:51:34 -0500 Original-Received: by mail-wg0-f51.google.com with SMTP id k14so27873677wgh.10 for ; Fri, 30 Jan 2015 08:51:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=IC4sXZGPqO8z9XfdESax5ozmve0czwOWm6DBSFl4w9k=; b=p5GaEGI0oE1cZclnrqZD/zbK6xbqprbTEgiJyWvi77+wcriuRCEIy8Hia6Qe1ELMFy V5Sbhmi4bkTXMIlSBkzXglVgFi2KcuVf+/cLzSAIWwAogbDAeruZ+a91rgw8I+0DpvBW UpxG2jIDZbpmNBUl235ztmpfogNTKgbTBdOEseqIVK9LI79x0YpLbPhc+F9sHNzmCf3s MREEICchXFbBpO3fvvS3XH7vJnCjI2bnhd6pt1tQwio8R59+4pwxJ0JyyQexOHlNh7fA g2cdnADUrSCFphvi2G7oHeIBdMZ3DCaApUcHv1zRZSeKJjzNUUUb5LeE10LTLcKQELyF 2DTw== X-Received: by 10.180.81.98 with SMTP id z2mr6699441wix.40.1422636693691; Fri, 30 Jan 2015 08:51:33 -0800 (PST) Original-Received: by 10.27.137.137 with HTTP; Fri, 30 Jan 2015 08:51:33 -0800 (PST) In-Reply-To: <54CBB31B.8040309@yahoo.fr> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::233 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:182079 Archived-At: On Fri, Jan 30, 2015 at 5:36 PM, Nicolas Richard wrote: > Le 30/01/2015 17:04, Oleh Krehel a =C3=A9crit : >> 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. You're right, of course, I was too fast to judge:). Exactly this is why we need such a function in the ELPA / core: it could be complex enough to do either the alist or the hash-table approach in an optimal way, since the homebrew stuff is bound to be simple and work good only in some cases. Oleh