Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.05; 'subject:Function': 0.07; '*args):': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'def': 0.14; 'suggest': 0.15; 'explicitly': 0.15; '100,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sadly': 0.16; 'subject:show': 0.16; 'takes,': 0.16; 'time.time()': 0.16; '{0}': 0.16; 'wrote:': 0.16; 'language': 0.19; '>>>': 0.20; 'lawrence': 0.22; '2015': 0.23; 'wrote': 0.23; 'url:profile': 0.23; 'header :In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'question': 0.26; 'header:X-Complaints-To:1': 0.26; 'function:': 0.29; '(which': 0.29; 'function': 0.30; 'subject:time': 0.31; 'seconds': 0.31; 'language.': 0.32; 'url:python': 0.33; 'needed': 0.34; 'could': 0.35; 'to:addr:python-list': 0.35; 'list': 0.35; 'asking': 0.35; 'sometimes': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'subject:: ': 0.37; 'received:org': 0.38; 'does': 0.39; 'url:docs': 0.39; 'to:addr:python.org': 0.39; 'mark': 0.40; 'skip:t 20': 0.40; 'url:3': 0.60; 'your': 0.60; 'here.': 0.61; 'times': 0.61; 'cheque': 0.63; 'our': 0.64; 'here': 0.66; 'results': 0.66; 'sunday': 0.72; 'quality': 0.72; 'cecil': 0.84; 'pythonistas,': 0.84; 'westerhof': 0.84; 'do:': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Function to show time to execute another function Date: Sun, 07 Jun 2015 11:16:30 +0100 References: <87k2vgowco.fsf@Equus.decebal.nl> <87fv64orly.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: host-78-147-183-129.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: <87fv64orly.fsf@Equus.decebal.nl> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433672222 news.xs4all.nl 2874 [2001:888:2000:d::a6]:51909 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 4854 X-Received-Body-CRC: 3290099008 Xref: csiph.com comp.lang.python:92224 On 07/06/2015 09:22, Cecil Westerhof wrote: > On Sunday 7 Jun 2015 09:39 CEST, Mark Lawrence wrote: > >> On 07/06/2015 07:39, Cecil Westerhof wrote: >>> Sometimes I just want to know how much time a function takes, but >>> at the same time I also want the result of the function. For this I >>> wrote the following function: def time_test(function, *args): >>> startTime = time.time() results = function(*args) endTime = >>> time.time() print('It took {0} seconds'.format(endTime - >>> startTime)) return results >>> >>> I can do: >>> time_test(test_random, 100, 10 ** 5) >>> This outputs: >>> It took 17.01685857772827 seconds >>> and returns: >>> (98592, 100833, 0.977775133140936) >>> >>> When executing: >>> time_test(test_random, 100, 10 ** 6) >>> it outputs: >>> It took 165.26371836662292 seconds >>> and returns: >>> (997103, 1002009, 0.9951038363926871) >>> >> >> https://docs.python.org/3/library/timeit.html >> https://docs.python.org/3/library/profile.html > > That only times the function. I explicitly mentioned I want both the > needed time AND the output. > > Sadly the quality of the answers on this list is going down. Here I > get an alternative that does only half what I want and when writing an > alternative for ‘!find’ I am told I could use ‘!find’ (which only > works in ipython, not python and which also not works with Windows). > I suggest that you stop asking so many question here. Get your cheque book and go for paid support. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence