From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.help Subject: Re: is there a emacs lisp timing command? Date: Tue, 24 Mar 2009 11:05:57 +0100 Organization: Arcor Message-ID: <86y6uvck1m.fsf@lola.quinscape.zz> References: <3a58c551-a1da-4794-8eb3-7de3c504c556@n7g2000prc.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1237891271 4695 80.91.229.12 (24 Mar 2009 10:41:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 24 Mar 2009 10:41:11 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 24 11:42:29 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Lm45E-0002v4-DN for geh-help-gnu-emacs@m.gmane.org; Tue, 24 Mar 2009 11:42:13 +0100 Original-Received: from localhost ([127.0.0.1]:60439 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lm43r-00038j-Kl for geh-help-gnu-emacs@m.gmane.org; Tue, 24 Mar 2009 06:40:47 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!news.glorb.com!news2.glorb.com!news.wiretrip.org!feeder1.cambriumusenet.nl!feed.tweaknews.nl!195.14.215.230.MISMATCH!news.netcologne.de!newsfeed-hp2.netcologne.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:sZfH434xzKvEY6VIUagrCHw+69E= Original-Lines: 43 Original-NNTP-Posting-Date: 24 Mar 2009 11:06:00 CET Original-NNTP-Posting-Host: e83be750.newsspool1.arcor-online.net Original-X-Trace: DXC=; hV^n8lIh70@4Fo<]lROoR1^YC2XCjHcb9CNU=RDY1`lDni3J>dXe39:TK0 Original-X-Complaints-To: usenet-abuse@arcor.de Original-Xref: news.stanford.edu gnu.emacs.help:167937 comp.emacs:98059 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:63226 Archived-At: Xah Lee 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