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

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

Re: Timing execution of function calls in Emacs lisp


From: Evans Winner
Subject: Re: Timing execution of function calls in Emacs lisp
Date: Thu, 05 Jun 2008 10:25:01 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Nordlöw <per.nordlow@gmail.com> writes:

    Is there a way to measure the execution time of function calls?
 
    Compare with following Matlab-snippet:
      tic; do_something(with_some_arg); toc
 
I am curious what the serious Elispers would do, so as bait
I wrote my own (almost certainly bad) attempt.  I understand
using `eval is bad form.  Still not too sure why.  Also, do
you need to do anything with the whatever it is your
function returns?  And I don't imagine this could be very
accurate.  Would something like this really have to be
implemented in C?  Maybe it already is.

(defvar tic nil)
(defvar toc nil)

(defun tic ()
  (setq tic (current-time)))

(defun toc ()
  (setq toc (current-time)))

(defun time (form)
  (progn
    (tic)
    (eval form)
    (toc)
    (time-subtract toc tic)))


reply via email to

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