unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Timing execution of function calls in Emacs lisp
@ 2008-06-05 13:24 Nordlöw
  2008-06-05 15:27 ` Lennart Borgman (gmail)
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Nordlöw @ 2008-06-05 13:24 UTC (permalink / raw)
  To: help-gnu-emacs

Is there a way to measure the execution time of function calls?

Compare with following Matlab-snippet:
  tic; do_something(with_some_arg); toc

In emacs lisp perhaps something like:
  (time FUNCTION ARGS...)

Thanks in advance,
Nordlöw


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Timing execution of function calls in Emacs lisp
  2008-06-05 13:24 Timing execution of function calls in Emacs lisp Nordlöw
@ 2008-06-05 15:27 ` Lennart Borgman (gmail)
  2008-06-05 16:25 ` Evans Winner
  2008-06-05 18:27 ` Nikolaj Schumacher
  2 siblings, 0 replies; 5+ messages in thread
From: Lennart Borgman (gmail) @ 2008-06-05 15:27 UTC (permalink / raw)
  To: Nordlöw; +Cc: help-gnu-emacs

Nordlöw wrote:
> Is there a way to measure the execution time of function calls?
> 
> Compare with following Matlab-snippet:
>   tic; do_something(with_some_arg); toc
> 
> In emacs lisp perhaps something like:
>   (time FUNCTION ARGS...)


Maybe the benchmark elisp library?




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Timing execution of function calls in Emacs lisp
  2008-06-05 13:24 Timing execution of function calls in Emacs lisp Nordlöw
  2008-06-05 15:27 ` Lennart Borgman (gmail)
@ 2008-06-05 16:25 ` Evans Winner
  2008-06-05 18:09   ` Nordlöw
  2008-06-05 18:27 ` Nikolaj Schumacher
  2 siblings, 1 reply; 5+ messages in thread
From: Evans Winner @ 2008-06-05 16:25 UTC (permalink / raw)
  To: help-gnu-emacs

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)))


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Timing execution of function calls in Emacs lisp
  2008-06-05 16:25 ` Evans Winner
@ 2008-06-05 18:09   ` Nordlöw
  0 siblings, 0 replies; 5+ messages in thread
From: Nordlöw @ 2008-06-05 18:09 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Timing execution of function calls in Emacs lisp
  2008-06-05 13:24 Timing execution of function calls in Emacs lisp Nordlöw
  2008-06-05 15:27 ` Lennart Borgman (gmail)
  2008-06-05 16:25 ` Evans Winner
@ 2008-06-05 18:27 ` Nikolaj Schumacher
  2 siblings, 0 replies; 5+ messages in thread
From: Nikolaj Schumacher @ 2008-06-05 18:27 UTC (permalink / raw)
  To: Nordlöw; +Cc: help-gnu-emacs

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

> Is there a way to measure the execution time of function calls?
>
> Compare with following Matlab-snippet:
>   tic; do_something(with_some_arg); toc
>
> In emacs lisp perhaps something like:
>   (time FUNCTION ARGS...)

Here's what I use.  It works well enough for my purposes.

(defmacro measure-time (&rest body)
  "Measure the time it takes to evaluate BODY."
  `(let ((time (current-time)))
     ,@body
     (message "%.06f" (float-time (time-since time)))))

It's used like this:

(measure-time
  (dotimes (i 100000)
    (1+ 1)))

regards,
Nikolaj Schumacher




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-06-05 18:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-05 13:24 Timing execution of function calls in Emacs lisp Nordlöw
2008-06-05 15:27 ` Lennart Borgman (gmail)
2008-06-05 16:25 ` Evans Winner
2008-06-05 18:09   ` Nordlöw
2008-06-05 18:27 ` Nikolaj Schumacher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).