Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-announce-list@python.org Delivered-To: python-announce-list@mail.python.org X-Spam-Status: OK 0.035 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'context': 0.05; 'subject:ANN': 0.07; 'callback': 0.09; 'instance.': 0.09; 'url:github': 0.09; 'python': 0.10; 'def': 0.13; 'b):': 0.16; 'skip:{ 30': 0.16; 'skip:` 10': 0.18; 'portion': 0.20; 'body,': 0.22; 'decorator': 0.22; 'function,': 0.22; 'pass': 0.22; 'code,': 0.23; '8bit%:5': 0.23; 'import': 0.24; 'feature': 0.24; 'module': 0.25; 'install': 0.25; "i've": 0.25; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'skip:u 20': 0.28; 'measure': 0.29; 'print': 0.30; 'code': 0.30; 'skip:s 30': 0.31; 'source': 0.33; 'received:google.com': 0.35; 'instance': 0.35; 'created': 0.36; 'thanks': 0.37; 'skip:s 40': 0.38; 'url:in': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'entire': 0.61; 'default': 0.61; 'watch': 0.62; 'more': 0.63; 'website:': 0.65; '\xc2\xa0\xc2\xa0': 0.66; '8bit%:21': 0.70; 'url:it': 0.70; 'receive': 0.71; 'andrea': 0.84; 'decorate': 0.84; 'pip': 0.84; 'execution,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=Upuv+vSCycm1SKgdX+jwlC+I8wKrux5DvsQ6OApQSQw=; b=ANB0LPQqimbhMsTDv6szLwPzMPU4vT1iOzplu7e8Lsf/FAJNrH/ky4sQYbLvkTQ9CK Ph4ZyxDsaKa0IXFWPhiBdPy25b1/bviYIrSGOwA66zLOzondV5oepfpLXNxuOpialGwO 2NaJej7jaQjXtxivi7sFvdtuptzbNfibxPPdV6JsCEpSgOsyURpBlmKpUMxvamE4uAKT S8zSWCShVLrY6CaYc15NomCFNQBMVbTO3xBF5/RoxdJMdNXzE3MsQM1yECLTKqt3juDX pNp22WbcmbSKf0mPSx9Pgip988lonQWVMlnhFxyx6g5mpqFwBqoC1zxd1AkIOzAulbIJ Sy6A== MIME-Version: 1.0 X-Received: by 10.180.87.225 with SMTP id bb1mr17884981wib.0.1442398793916; Wed, 16 Sep 2015 03:19:53 -0700 (PDT) Date: Wed, 16 Sep 2015 12:19:53 +0200 Subject: ANN lauda 1.1.0 From: Andrea Stagi To: python-announce-list@python.org X-Mailman-Approved-At: Wed, 16 Sep 2015 12:24:25 +0200 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.20+ X-BeenThere: python-announce-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: Announcement-only list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Approved: python-announce-list@python.org Newsgroups: comp.lang.python.announce Message-ID: Lines: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1442399067 news.xs4all.nl 23735 [2001:888:2000:d::a6]:33034 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python.announce:1859 I've created lauda, a little python module to measure time. Thanks a lot to Jes=C3=BAs Espino (@jespinog) for the new context manager feature You can install it with pip install lauda you can find the source code on Github: https://github.com/astagi/lauda You can use lauda StopWatch to measure a portion of code from lauda import StopWatch watch =3D StopWatch() watch.start() for i in range(10000000): pass watch.stop() print ('Time spent in range {0}'.format(watch.elapsed_time)) If you want to measure an entire function execution, you can decorate it using the stopwatch decorator from lauda import stopwatch @stopwatch def awesome_mul(a, b): return a * b By default stopwatch decorator will print the time spent inside the decorated function, if you want more control you can pass to your decorator a callback that will receive a StopWatch instance and the decorated function. from lauda import stopwatch def stopwatch_sum_cb(watch, function): print ('Time spent {0}'.format(watch.elapsed_time)) @stopwatch(callback=3Dstopwatch_sum_cb) def awesome_sum(a, b): return a + b If you want to measure a block of code, you can use the `stopwatchcm` context manager from lauda import stopwatchcm with stopwatchcm(): c =3D a * b By default `stopwatchcm` context manager will print the time spent inside the context manager body, if you want more control you can pass to your context manager a callback that will receive a `StopWatch` instance. from lauda import stopwatchcm def stopwatch_sum_cb(watch): print ('Time spent {0}'.format(watch.elapsed_time)) with stopwatchcm(callback=3Dstopwatch_sum_cb): c =3D a + b --=20 Andrea Stagi (@4stagi) - Develover @Nephila Job profile: http://linkedin.com/in/andreastagi Website: http://4spills.blogspot.it/ Github: http://github.com/astagi