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

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

Re: is there a emacs lisp timing command?


From: David Kastrup
Subject: Re: is there a emacs lisp timing command?
Date: Tue, 24 Mar 2009 11:05:57 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Xah Lee <xahlee@gmail.com> writes:

> is there a elisp command like timing, that returns the time a function
> took?
>
> while testing some performance issues, i tried to write one.
>
> (defun xx-timing ()
>   "returns the timing."
>   (interactive)
>   (let (starttime endtime)
>     (setq starttime (current-time))
>
>     ;; some function here
>     (sleep-for 0 5)
>
>     (setq endtime (current-time))
>     (message "%f" (+ (* (- (elt endtime 0)
>                            (elt starttime 0)) 65536)
>                      (- (elt endtime 1)
>                         (elt starttime 1))
>                      (* (- (elt endtime 2)
>                            (elt starttime 2)) 0.001)))
>     ))
>
> but after about 20 minutes on this, i gave up. It seems to me, when
> microseconds is involved (returned by current-time), the result is
> weired. I don't see any logical problem in my code, but the above code
> is obvious wrong, often returning results some 70 seconds extra
> whenever microseconds is involved.

65536000000 is not a number representable in Elisp integers.

Why don't you use the time-subtract command and/or the float-time
command?

Note: the float-time command DOC string talks about a time form
(HIGH LOW . IGNORED).  Quite counterintuively, IGNORED is not ignored
but rather gives microseconds.  So you can use this function just fine.
I have made a bug report.

-- 
David Kastrup


reply via email to

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