help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: return first element in list with certain property


From: Emanuel Berg
Subject: Re: return first element in list with certain property
Date: Tue, 06 Mar 2018 10:29:07 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

> OK, but without having tested it, is there
> any reason to favor it to `cl-find-if'?

Now I have tested it and it seems
"list-find-if" is a little faster than
`cl-find-if'!

So good job even tho I will stick to CL
thank you :)

(require 'cl-lib)

(defun list-find-if (pred xs)
  (while (and (consp xs)
              (not (funcall pred (car xs))) )
    (pop xs) )
  (car xs) )

(let*((max-value          1000000)
      (random-list        (create-random-list max-value max-value))
      (bigger-than-random (lambda (e) (> e (random max-value)))) )
  (message "Testing for %s" max-value)
  (message
   "Test list-find-if: %s"
   (measure-time (list-find-if bigger-than-random random-list)) )
  (message
   "Test cl-find-if: %s"
   (measure-time (cl-find-if   bigger-than-random random-list)) )
  )

"create-random-list" and "measure-time" here:

    http://user.it.uu.se/~embe8573/emacs-init/measure.el

-- 
underground experts united
http://user.it.uu.se/~embe8573


reply via email to

[Prev in Thread] Current Thread [Next in Thread]