* is there a emacs lisp timing command?
@ 2009-03-24 1:57 Xah Lee
2009-03-24 6:12 ` thierry.volpiatto
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Xah Lee @ 2009-03-24 1:57 UTC (permalink / raw)
To: help-gnu-emacs
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.
anyone has written a timing command somewhere?
This is on:
GNU Emacs 22.2.1 (powerpc-apple-darwin8.11.0, Carbon Version 1.6.0) of
2008-04-05 on g5.tokyo.stp.isas.jaxa.jp
PowerPC G5, osx 10.4.11.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: is there a emacs lisp timing command?
2009-03-24 1:57 is there a emacs lisp timing command? Xah Lee
@ 2009-03-24 6:12 ` thierry.volpiatto
2009-03-24 6:35 ` thierry.volpiatto
2009-03-24 7:30 ` Helmut Eller
` (3 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: thierry.volpiatto @ 2009-03-24 6:12 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
have a look at traverselisp.el,
the function `traverse-deep-rfind' have a timer.
http://www.emacswiki.org/cgi-bin/emacs/traverselisp.el
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.
>
> anyone has written a timing command somewhere?
>
> This is on:
> GNU Emacs 22.2.1 (powerpc-apple-darwin8.11.0, Carbon Version 1.6.0) of
> 2008-04-05 on g5.tokyo.stp.isas.jaxa.jp
>
> PowerPC G5, osx 10.4.11.
>
> Xah
> ∑ http://xahlee.org/
>
> ☄
>
>
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: is there a emacs lisp timing command?
2009-03-24 6:12 ` thierry.volpiatto
@ 2009-03-24 6:35 ` thierry.volpiatto
2009-03-24 6:46 ` thierry.volpiatto
0 siblings, 1 reply; 9+ messages in thread
From: thierry.volpiatto @ 2009-03-24 6:35 UTC (permalink / raw)
To: help-gnu-emacs
And this can help also:(adapt for your case with traverselisp code).
(defun current-human-time ()
(let* ((cur-time (decode-time (current-time)))
(h (int-to-string (nth 2 cur-time)))
(m (int-to-string (nth 1 cur-time)))
(s (int-to-string (nth 0 cur-time))))
(message "%s" (concat h ":" m ":" s))))
(defvar my-time nil)
(defun start-watch ()
(setq my-time (run-with-timer 1 1 'current-human-time)))
(defun stop-watch ()
(cancel-timer my-time)
(setq my-time nil))
thierry.volpiatto@gmail.com writes:
> Hi,
> have a look at traverselisp.el,
> the function `traverse-deep-rfind' have a timer.
> http://www.emacswiki.org/cgi-bin/emacs/traverselisp.el
>
> 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.
>>
>> anyone has written a timing command somewhere?
>>
>> This is on:
>> GNU Emacs 22.2.1 (powerpc-apple-darwin8.11.0, Carbon Version 1.6.0) of
>> 2008-04-05 on g5.tokyo.stp.isas.jaxa.jp
>>
>> PowerPC G5, osx 10.4.11.
>>
>> Xah
>> ∑ http://xahlee.org/
>>
>> ☄
>>
>>
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: is there a emacs lisp timing command?
2009-03-24 6:35 ` thierry.volpiatto
@ 2009-03-24 6:46 ` thierry.volpiatto
0 siblings, 0 replies; 9+ messages in thread
From: thierry.volpiatto @ 2009-03-24 6:46 UTC (permalink / raw)
To: help-gnu-emacs
hoops! i didn't remember i had this one also:
(defmacro chrono-func (output fn &rest args)
`(let ((init-time (cadr (current-time)))
(final-time)
(final-result))
(setq final-result (funcall ,fn ,@args))
(setq final-time (- (cadr (current-time)) init-time))
(message "Time:%2s s" final-time)
(when ,output
final-result)))
May be it's exactly what you want.
thierry.volpiatto@gmail.com writes:
> And this can help also:(adapt for your case with traverselisp code).
>
>
> (defun current-human-time ()
> (let* ((cur-time (decode-time (current-time)))
> (h (int-to-string (nth 2 cur-time)))
> (m (int-to-string (nth 1 cur-time)))
> (s (int-to-string (nth 0 cur-time))))
> (message "%s" (concat h ":" m ":" s))))
>
> (defvar my-time nil)
> (defun start-watch ()
> (setq my-time (run-with-timer 1 1 'current-human-time)))
>
> (defun stop-watch ()
> (cancel-timer my-time)
> (setq my-time nil))
>
> thierry.volpiatto@gmail.com writes:
>
>> Hi,
>> have a look at traverselisp.el,
>> the function `traverse-deep-rfind' have a timer.
>> http://www.emacswiki.org/cgi-bin/emacs/traverselisp.el
>>
>> 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.
>>>
>>> anyone has written a timing command somewhere?
>>>
>>> This is on:
>>> GNU Emacs 22.2.1 (powerpc-apple-darwin8.11.0, Carbon Version 1.6.0) of
>>> 2008-04-05 on g5.tokyo.stp.isas.jaxa.jp
>>>
>>> PowerPC G5, osx 10.4.11.
>>>
>>> Xah
>>> ∑ http://xahlee.org/
>>>
>>> ☄
>>>
>>>
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: is there a emacs lisp timing command?
2009-03-24 1:57 is there a emacs lisp timing command? Xah Lee
2009-03-24 6:12 ` thierry.volpiatto
@ 2009-03-24 7:30 ` Helmut Eller
2009-03-24 8:11 ` thierry.volpiatto
2009-03-24 10:05 ` David Kastrup
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Helmut Eller @ 2009-03-24 7:30 UTC (permalink / raw)
To: help-gnu-emacs
* Xah Lee [2009-03-24 02:57+0100] writes:
> anyone has written a timing command somewhere?
I've use this for ages:
;;;; CL-like time macro
(defmacro time (form)
(autoload 'elp-elapsed-time "elp")
(let ((start (make-symbol "#:start")))
`(let ((,start (current-time)))
(prog1 ,form
(princ (format "Elapsed time: %.2f sec \n"
(elp-elapsed-time ,start (current-time))))))))
Helmut.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: is there a emacs lisp timing command?
2009-03-24 7:30 ` Helmut Eller
@ 2009-03-24 8:11 ` thierry.volpiatto
0 siblings, 0 replies; 9+ messages in thread
From: thierry.volpiatto @ 2009-03-24 8:11 UTC (permalink / raw)
To: help-gnu-emacs
Have a look also at all the elp-instrument-* functions
Helmut Eller <eller.helmut@gmail.com> writes:
> * Xah Lee [2009-03-24 02:57+0100] writes:
>
>> anyone has written a timing command somewhere?
>
> I've use this for ages:
>
> ;;;; CL-like time macro
> (defmacro time (form)
> (autoload 'elp-elapsed-time "elp")
> (let ((start (make-symbol "#:start")))
> `(let ((,start (current-time)))
> (prog1 ,form
> (princ (format "Elapsed time: %.2f sec \n"
> (elp-elapsed-time ,start (current-time))))))))
>
>
> Helmut.
>
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: is there a emacs lisp timing command?
2009-03-24 1:57 is there a emacs lisp timing command? Xah Lee
2009-03-24 6:12 ` thierry.volpiatto
2009-03-24 7:30 ` Helmut Eller
@ 2009-03-24 10:05 ` David Kastrup
2009-03-24 20:25 ` Nikolaj Schumacher
[not found] ` <mailman.3921.1237926315.31690.help-gnu-emacs@gnu.org>
4 siblings, 0 replies; 9+ messages in thread
From: David Kastrup @ 2009-03-24 10:05 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: is there a emacs lisp timing command?
2009-03-24 1:57 is there a emacs lisp timing command? Xah Lee
` (2 preceding siblings ...)
2009-03-24 10:05 ` David Kastrup
@ 2009-03-24 20:25 ` Nikolaj Schumacher
[not found] ` <mailman.3921.1237926315.31690.help-gnu-emacs@gnu.org>
4 siblings, 0 replies; 9+ messages in thread
From: Nikolaj Schumacher @ 2009-03-24 20:25 UTC (permalink / raw)
To: Xah Lee; +Cc: help-gnu-emacs
Xah Lee <xahlee@gmail.com> wrote:
> is there a elisp command like timing, that returns the time a function
> took?
Seems like everybody here has written their own, but Emacs does come with:
benchmark-run and benchmark-run-compiled.
It takes garbage collection into account, which can explain fluctuating
results.
regards,
Nikolaj Schumacher
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: is there a emacs lisp timing command?
[not found] ` <mailman.3921.1237926315.31690.help-gnu-emacs@gnu.org>
@ 2009-03-24 22:07 ` Xah Lee
0 siblings, 0 replies; 9+ messages in thread
From: Xah Lee @ 2009-03-24 22:07 UTC (permalink / raw)
To: help-gnu-emacs
On Mar 24, 1:25 pm, Nikolaj Schumacher <m...@nschum.de> wrote:
> Xah Lee <xah...@gmail.com> wrote:
> > is there a elisp command like timing, that returns the time a function
> > took?
>
> Seems like everybody here has written their own, but Emacs does come with:
> benchmark-run and benchmark-run-compiled.
>
> It takes garbage collection into account, which can explain fluctuating
> results.
Thank you all for the help.
After reading the replies, it turns out my error was that i mistook
microsecond to be 10^-3 but it should be 10^-6.
Thanks Nik for the benchmark-run. That'll be helpful too, and the elp
profiler down the road.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2009-03-24 22:07 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-24 1:57 is there a emacs lisp timing command? Xah Lee
2009-03-24 6:12 ` thierry.volpiatto
2009-03-24 6:35 ` thierry.volpiatto
2009-03-24 6:46 ` thierry.volpiatto
2009-03-24 7:30 ` Helmut Eller
2009-03-24 8:11 ` thierry.volpiatto
2009-03-24 10:05 ` David Kastrup
2009-03-24 20:25 ` Nikolaj Schumacher
[not found] ` <mailman.3921.1237926315.31690.help-gnu-emacs@gnu.org>
2009-03-24 22:07 ` Xah Lee
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).