all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: thierry.volpiatto@gmail.com
To: help-gnu-emacs@gnu.org
Subject: Re: is there a emacs lisp timing command?
Date: Tue, 24 Mar 2009 07:46:19 +0100	[thread overview]
Message-ID: <87wsafpgec.fsf@tux.homenetwork> (raw)
In-Reply-To: 871vsnqvge.fsf@tux.homenetwork

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





  reply	other threads:[~2009-03-24  6:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wsafpgec.fsf@tux.homenetwork \
    --to=thierry.volpiatto@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.