Yesterday I declared emacs bankruptcy and now I'm writing my init.el file from scratch.

I'd like to call a function several times within my init.el file to output the current loading times. I've found this piece of code which only tells the final loading time:

(when window-system
  (let ((elapsed (float-time (time-subtract (current-time)
    (message "Loading %s...done (%.3fs)" load-file-name elapsed))

  (add-hook 'after-init-hook
            `(lambda ()
               (let ((elapsed (float-time (time-subtract (current-time)
                 (message "Loading %s...done (%.3fs) [after-init]"
                          ,load-file-name elapsed)))

So far I failed any attempt to 'extract' some bits and bobs from there to create the function I look for.

Although I've using Emacs for several years, I have no idea about elisp. All I do is copy + paste + edit code, which is a shame.

Please don't accuse me of not even try it because I had spent a good couple of hours with zero results. I'd put some of the code I've written but I don't think it would help to anything apart from embarrass myself.

I know that there are several packages which help profiling Emacs configuration files but that's not really what I'm kindly asking here. I'd like some help to write a little function.

1 Answer 1


Right, I think I managed to do it. This is what I've written:

(defun get-time (package-loaded)
  (let ((elapsed (float-time (time-subtract (current-time) emacs-start-time))))
    (message "loading %s package...done (%.3fs)" package-loaded elapsed)))

Then I can call that function like this:

(get-time "use-package")
(get-time "yasnippet")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.