[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Timing execution of function calls in Emacs lisp
From: |
Nordlöw |
Subject: |
Re: Timing execution of function calls in Emacs lisp |
Date: |
Thu, 5 Jun 2008 11:09:35 -0700 (PDT) |
User-agent: |
G2/1.0 |
On 5 Juni, 18:25, Evans Winner <tho...@timbral.net> wrote:
> Nordlöw <per.nord...@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)))
benchmark-run() does the trick!
Many thanks,
Nordlöw