[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Would seq-range and seq-mapcat be useful?
From: |
Nicolas Richard |
Subject: |
Re: Would seq-range and seq-mapcat be useful? |
Date: |
Fri, 30 Jan 2015 17:36:43 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 |
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.
- Re: Would seq-range and seq-mapcat be useful?, (continued)
- Re: Would seq-range and seq-mapcat be useful?, Stefan Monnier, 2015/01/29
- Re: Would seq-range and seq-mapcat be useful?, Nicolas Petton, 2015/01/29
- Re: Would seq-range and seq-mapcat be useful?, Stefan Monnier, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Oleh Krehel, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Nicolas Petton, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Oleh Krehel, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Nicolas Richard, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Oleh Krehel, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Oleh Krehel, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?,
Nicolas Richard <=
- Re: Would seq-range and seq-mapcat be useful?, Oleh Krehel, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Nicolas Petton, 2015/01/30
What about seq-slice? (Was: Would seq-range and seq-mapcat be useful?), Mark Oteiza, 2015/01/30