Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!newsfeed.xs4all.nl!newsfeed3.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.006 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; 'def': 0.14; '100,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:show': 0.16; 'takes,': 0.16; 'time.time()': 0.16; '{0}': 0.16; 'wrote:': 0.16; 'language': 0.19; 'lawrence': 0.22; 'wrote': 0.23; 'url:profile': 0.23; 'header:In-Reply-To:1': 0.24; 'header :User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'function:': 0.29; 'function': 0.30; 'subject:time': 0.31; 'seconds': 0.31; 'language.': 0.32; 'url:python': 0.33; 'to:addr :python-list': 0.35; 'sometimes': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'subject:: ': 0.37; 'received:org': 0.38; 'url:docs': 0.39; 'to:addr:python.org': 0.39; 'mark': 0.40; 'skip:t 20': 0.40; 'url:3': 0.60; 'our': 0.64; 'charset:windows-1252': 0.65; 'results': 0.66; '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 08:39:20 +0100 References: <87k2vgowco.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit 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: <87k2vgowco.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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433662792 news.xs4all.nl 2968 [2001:888:2000:d::a6]:60139 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3907 X-Received-Body-CRC: 2767174571 Xref: csiph.com comp.lang.python:92209 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 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence