From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nikolaj Schumacher Newsgroups: gmane.emacs.help Subject: Re: Timing execution of function calls in Emacs lisp Date: Thu, 05 Jun 2008 20:27:46 +0200 Message-ID: References: <50d4f479-3c3e-4049-ba88-c989174118dc@j22g2000hsf.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1212690500 1790 80.91.229.12 (5 Jun 2008 18:28:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Jun 2008 18:28:20 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: =?utf-8?Q?Nordl=C3=B6w?= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 05 20:29:02 2008 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 1K4KCr-00038G-8R for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Jun 2008 20:29:01 +0200 Original-Received: from localhost ([127.0.0.1]:42381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K4KC4-00043z-Eb for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Jun 2008 14:28:12 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K4KBj-00043T-8N for help-gnu-emacs@gnu.org; Thu, 05 Jun 2008 14:27:51 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K4KBh-000439-SU for help-gnu-emacs@gnu.org; Thu, 05 Jun 2008 14:27:50 -0400 Original-Received: from [199.232.76.173] (port=40778 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K4KBh-000436-Nd for help-gnu-emacs@gnu.org; Thu, 05 Jun 2008 14:27:49 -0400 Original-Received: from fmmailgate02.web.de ([217.72.192.227]:42584) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K4KBh-0004IK-TS for help-gnu-emacs@gnu.org; Thu, 05 Jun 2008 14:27:50 -0400 Original-Received: from smtp07.web.de (fmsmtp07.dlan.cinetic.de [172.20.5.215]) by fmmailgate02.web.de (Postfix) with ESMTP id E40FBE03E4BE; Thu, 5 Jun 2008 20:27:47 +0200 (CEST) Original-Received: from [77.189.13.10] (helo=thursday) by smtp07.web.de with asmtp (WEB.DE 4.109 #226) id 1K4KBf-000204-00; Thu, 05 Jun 2008 20:27:47 +0200 In-Reply-To: <50d4f479-3c3e-4049-ba88-c989174118dc@j22g2000hsf.googlegroups.com> (=?utf-8?Q?=22Nordl=C3=B6w=22's?= message of "Thu\, 5 Jun 2008 06\:24\:45 -0700 \(PDT\)") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (darwin) X-Sender: n_schumacher@web.de X-Provags-ID: V01U2FsdGVkX18mGdyRGvci4FDGi86A30GPNSZwGNxIPAiU38dX 6ADgnyWu2dsmt9LvN33n/MVNs7MGPg7l4baN8AW8lvTNZn9Y3v pyNU5gszACWa/cj8GK6A== X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 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:54484 Archived-At: Nordl=C3=B6w 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