Hi there,
In this interesting discussion with Alexander Miller, he mentioned that directory-files is faster when called in a temp buffer. This quick test seems to show that it is indeed:
#+BEGIN_SRC elisp
(defun f--collect-entries--tb (path recursive)
(with-temp-buffer
(let (result
(entries
(-reject
(lambda (file)
(or
(equal (f-filename file) ".")
(equal (f-filename file) "..")))
(directory-files path t))))
(cond (recursive
(-map
(lambda (entry)
(if (f-file? entry)
(setq result (cons entry result))
(when (f-directory? entry)
(setq result (cons entry result))
(setq result (append result (f--collect-entries entry recursive))))))
entries))
(t (setq result entries)))
result)))
(list (cons "without temp buffer"
(progn
(garbage-collect)
(benchmark-run-compiled 100
(f--collect-entries "~/.emacs.d" nil))))
(cons "with temp buffer"
(progn
(garbage-collect)
(benchmark-run-compiled 100
(f--collect-entries--tb "~/.emacs.d" nil)))))
#+END_SRC
#+RESULTS:
| without temp buffer | 0.31999160200000004 | 0 | 0.0 |
| with temp buffer | 0.191897104 | 0 | 0.0 |
I thought I should let you know in so that it could be added to f--collect-entries. Seems like a nice, free optimization. :)
Thanks for your work on f.el!
Hi there,
In this interesting discussion with Alexander Miller, he mentioned that
directory-filesis faster when called in a temp buffer. This quick test seems to show that it is indeed:I thought I should let you know in so that it could be added to
f--collect-entries. Seems like a nice, free optimization. :)Thanks for your work on f.el!