Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1a.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.093 X-Spam-Evidence: '*H*': 0.82; '*S*': 0.00; 'explicitly': 0.05; 'function,': 0.09; 'true)': 0.09; 'runs': 0.10; 'def': 0.12; 'arg):': 0.16; 'arg,': 0.16; 'cached': 0.16; 'caching': 0.16; 'called.': 0.16; 'loops': 0.16; 'objects.': 0.16; 'time.time()': 0.16; 'wrote:': 0.18; 'passing': 0.19; '>>>': 0.22; 'header:User- Agent:1': 0.23; 'skip:{ 20': 0.24; 'regardless': 0.24; 'first,': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'figure': 0.32; 'run': 0.32; 'subject:the': 0.34; "i'd": 0.34; 'created': 0.35; 'something': 0.35; 'objects': 0.35; 'test': 0.35; 'but': 0.35; 'false': 0.36; 'responsible': 0.36; 'two': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'called': 0.40; 'dave': 0.60; 'ian': 0.60; 'is.': 0.60; 'took': 0.61; "you're": 0.61; 'first': 0.61; 'charset:windows-1252': 0.65; 'received:74.208': 0.68; 'reverse': 0.68; 'caused': 0.69; 'default': 0.69; 'other.': 0.75; '2015': 0.84; '3:00': 0.84; 'difference.': 0.84; 'noise': 0.84; 'angel': 0.91; 'cause,': 0.91 Date: Tue, 05 May 2015 17:55:01 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Throw the cat among the pigeons References: <87h9rvm576.fsf@Equus.decebal.nl> <871tixlmp6.fsf@Equus.decebal.nl> <750db03b-e393-43ff-9ccf-5cc050af7324@googlegroups.com> <87zj5jf15q.fsf@Equus.decebal.nl> <55490FAE.8070501@davea.name> <55492F55.1020105@davea.name> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:oE29Xz38CLPlvBqQmVVDfR2cwcX1K9DfvObmTKH8O3Rh30JX2Wp PCgXajKqsLGNowhLQ8NAZuUJNeJtGkQqUOTECINQd1kg5nJOy7lHhPDFY/GhKTVCkjiG4MW NPmi+CuNevOJcuAK1iQez8KYggCuzI1VkPaAK5D3+jttTK1hnQ+bidRlzMTcttkiR5WUAO1 xYAbddWrZJ4cfzQdw8XBQ== X-UI-Out-Filterresults: notjunk:1; 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430862924 news.xs4all.nl 2828 [2001:888:2000:d::a6]:46897 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90005 On 05/05/2015 05:39 PM, Ian Kelly wrote: > On Tue, May 5, 2015 at 3:23 PM, Ian Kelly wrote: >> On Tue, May 5, 2015 at 3:00 PM, Dave Angel wrote: >>> def loop(func, funcname, arg): >>> start = time.time() >>> for i in range(repeats): >>> func(arg, True) >>> print("{0}({1}) took {2:7.4}".format(funcname, arg, time.time()-start)) >>> >>> start = time.time() >>> for i in range(repeats): >>> func(arg) >>> print("{0}({1}) took {2:7.4}".format(funcname, arg, time.time()-start)) >> >> Note that you're explicitly passing True in one case but leaving the >> default in the other. I don't know whether that might be responsible >> for the difference you're seeing. > > I don't think that's the cause, but I do think that it has something > to do with the way the timing is being run. When I run your loop > function, I do observe the difference. If I reverse the order so that > the False case is tested first, I observe the opposite. That is, the > slower case is consistently the one that is timed *first* in the loop > function, regardless of which case that is. > I created two functions and called them with Timeit(), and the difference is now below 3% And when I take your lead and double the loop() function so it runs each test twice, I get steadily decreasing numbers. I think all of this has been noise caused by the caching of objects including function objects. I was surprised by this, as the loops are small enough I'd figure the function object would be fully cached the first time it was called. -- DaveA