Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #92251

Re: Function to show time to execute another function

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!news2.arglkargh.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!newsfeed.pionier.net.pl!feed.xsnews.nl!border03.ams.xsnews.nl!feeder03.ams.xsnews.nl!abp001.ams.xsnews.nl!frontend-F10-13.ams.news.kpn.nl
From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.python
Subject Re: Function to show time to execute another function
Organization Decebal Computing
References <87k2vgowco.fsf@Equus.decebal.nl> <55740ecf$0$12978$c3e8da3$5496439d@news.astraweb.com>
X-Face "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR<J%a^F2lh4[N~Yz4 nSp#c+aQo1b5=?HcNEkQ7QzF<])O3X4MDL/AYjys&*mt>,v+Pti8=Vi/Z"g^?b"E
X-Homepage http://www.decebal.nl/
Date Sun, 07 Jun 2015 14:58:40 +0200
Message-ID <87lhfvoetb.fsf@Equus.decebal.nl> (permalink)
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
Cancel-Lock sha1:KkBOJ2JCOjJpg00T/GwBhwKUkoE=
MIME-Version 1.0
Content-Type text/plain
Lines 26
NNTP-Posting-Host 81.207.62.244
X-Trace 1433682951 news.kpn.nl 21127 81.207.62.244@kpn/81.207.62.244:33306
Xref csiph.com comp.lang.python:92251

Show key headers only | View raw


On Sunday  7 Jun 2015 11:28 CEST, Steven D'Aprano wrote:

> Here is a simple example:
>
> http://code.activestate.com/recipes/577896-benchmark-code-with-the-with-statement/
I use that now in my function:
#-----------------------------------------------------------------------
def time_test(function, arguments, print_time = True):
    t = Timer()
    with t:
        results     = function(*arguments)
    used_time = t.interval
    if print_time:
        print('It took {0} seconds'.format(used_time))
    else:
        results = (used_time, results)
    return results
#-----------------------------------------------------------------------

I find that neater. It also looks like the time value is a little
less, but I did not really measure it.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Function to show time to execute another function Cecil Westerhof <Cecil@decebal.nl> - 2015-06-07 08:39 +0200
  Re: Function to show time to execute another function Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-07 08:39 +0100
    Re: Function to show time to execute another function Cecil Westerhof <Cecil@decebal.nl> - 2015-06-07 10:22 +0200
      Re: Function to show time to execute another function Luca Menegotto <otlucaDELETE@DELETEyahoo.it> - 2015-06-07 11:06 +0200
        Is it a newsgroup or a list? random832@fastmail.us - 2015-06-07 07:20 -0400
          Re: Is it a newsgroup or a list? Steven D'Aprano <steve@pearwood.info> - 2015-06-07 21:45 +1000
            Re: Is it a newsgroup or a list? Chris Warrick <kwpolska@gmail.com> - 2015-06-07 15:10 +0200
            Re: Is it a newsgroup or a list? Luca Menegotto <otlucaDELETE@DELETEyahoo.it> - 2015-06-07 16:12 +0200
        Re: Function to show time to execute another function Cecil Westerhof <Cecil@decebal.nl> - 2015-06-07 13:53 +0200
        Re: Is it a newsgroup or a list? Tim Golden <mail@timgolden.me.uk> - 2015-06-07 14:57 +0100
      Re: Function to show time to execute another function Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-07 11:16 +0100
        [OT] Re: Function to show time to execute another function Marko Rauhamaa <marko@pacujo.net> - 2015-06-07 14:02 +0300
          Re: [OT] Re: Function to show time to execute another function Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-07 12:12 +0100
        Re: Function to show time to execute another function Steven D'Aprano <steve@pearwood.info> - 2015-06-07 21:29 +1000
        Re: Function to show time to execute another function Cecil Westerhof <Cecil@decebal.nl> - 2015-06-07 14:03 +0200
      Re: Function to show time to execute another function Tim Golden <mail@timgolden.me.uk> - 2015-06-07 12:05 +0100
        Re: Function to show time to execute another function Cecil Westerhof <Cecil@decebal.nl> - 2015-06-07 14:43 +0200
      Re: Function to show time to execute another function Laura Creighton <lac@openend.se> - 2015-06-07 15:03 +0200
      Re: Function to show time to execute another function Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-06-07 20:51 +0200
        Re: Function to show time to execute another function Cecil Westerhof <Cecil@decebal.nl> - 2015-06-07 22:35 +0200
          Re: Function to show time to execute another function Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-06-08 07:04 +0200
            Re: Function to show time to execute another function Cecil Westerhof <Cecil@decebal.nl> - 2015-06-08 08:32 +0200
  Re: Function to show time to execute another function Steven D'Aprano <steve@pearwood.info> - 2015-06-07 19:28 +1000
    Re: Function to show time to execute another function Luca Menegotto <otlucaDELETE@DELETEyahoo.it> - 2015-06-07 11:44 +0200
    Re: Function to show time to execute another function Cecil Westerhof <Cecil@decebal.nl> - 2015-06-07 14:14 +0200
    Re: Function to show time to execute another function Cecil Westerhof <Cecil@decebal.nl> - 2015-06-07 14:58 +0200
  Re: Function to show time to execute another function Steven D'Aprano <steve@pearwood.info> - 2015-06-07 19:51 +1000
    Re: Function to show time to execute another function Cecil Westerhof <Cecil@decebal.nl> - 2015-06-07 14:27 +0200
  Re: Function to show time to execute another function Cecil Westerhof <Cecil@decebal.nl> - 2015-06-07 11:31 +0200
  Re: Is it a newsgroup or a list? Gene Heskett <gheskett@wdtv.com> - 2015-06-07 11:49 -0400
  Re: Is it a newsgroup or a list? Larry Martell <larry.martell@gmail.com> - 2015-06-07 11:56 -0400

csiph-web