Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone01.am1.xlned.com!bcyclone01.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.071 X-Spam-Evidence: '*H*': 0.87; '*S*': 0.01; 'skip:[ 20': 0.04; 'explicitly': 0.05; 'true)': 0.09; 'def': 0.12; '"from': 0.16; 'arg):': 0.16; 'arg,': 0.16; 'time.time()': 0.16; 'wrote:': 0.18; 'module': 0.19; 'passing': 0.19; '>>>': 0.22; 'code,': 0.22; 'import': 0.22; 'skip:{ 20': 0.24; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; 'see,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; 'subject:the': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'responsible': 0.36; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'dave': 0.60; 'skip:t 30': 0.61; 'took': 0.61; "you're": 0.61; 'default': 0.69; 'other.': 0.75; '(probably': 0.84; '2015': 0.84; '3:00': 0.84; 'average.': 0.84; 'min': 0.84; 'angel': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=q8FYX1ByhMBSeQLVRBYINN5IhMsbmEadXiE4hAgZTHc=; b=XcBdtxACkpo7PLGkcx2qJLU4ib6jpE19fjPflcYLrgExnq/w2CpkXQgOnyaThjCbuW na2SXFPWBj24XzPNrCR7gQ9ga0L6Y+462tfTyprYOAU+zk2TAxmnOQt7J61ho2R4YDgW jJQpfH2eKBmKVfo4l2CzDqfYsLtSuF0gpxvYtGsW0at2sORVql57r4H0NBS6FgVDsC5q Gr07l3kefzPLMDp6x1wjQOp9rmPt0jEnTXxk49j/JJ+4Oe9k7xH3awE1R1Le/tLxeRbB l44koTfH4/CWmMSI6DhjfYgNZ/9DnQabLHafis3t00mv2Txd1gfzQNYn/PoNw0Q4iPPr DkHQ== X-Received: by 10.50.30.105 with SMTP id r9mr4461150igh.11.1430861078794; Tue, 05 May 2015 14:24:38 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <55492F55.1020105@davea.name> 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> From: Ian Kelly Date: Tue, 5 May 2015 15:23:58 -0600 Subject: Re: Throw the cat among the pigeons To: Python Content-Type: text/plain; charset=UTF-8 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430861087 news.xs4all.nl 2882 [2001:888:2000:d::a6]:46088 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 4898 X-Received-Body-CRC: 3041312533 Xref: csiph.com comp.lang.python:90002 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. Also, it's best to use the timeit module for timing code, e.g.: >>> from timeit import Timer >>> t1 = Timer("factorial_iterative(100000, False)", "from __main__ import factorial_iterative") >>> t1.repeat(10, number=1) [3.8517245299881324, 3.7571076710009947, 3.7780062559759244, 3.848508063936606, 3.7627131739864126, 3.8278848479967564, 3.776115525048226, 3.83024005102925, 3.8322679550619796, 3.8195601429324597] >>> min(_), sum(_) / len(_) (3.7571076710009947, 3.8084128216956743) >>> t2 = Timer("factorial_iterative(100000, True)", "from __main__ import factorial_iterative") >>> t2.repeat(10, number=1) [3.8363616950809956, 3.753201302024536, 3.7838632150087506, 3.7670978900277987, 3.805312803015113, 3.7682680500438437, 3.856655619922094, 3.796431727008894, 3.8224815409630537, 3.765664782957174] >>> min(_), sum(_) / len(_) (3.753201302024536, 3.7955338626052253) As you can see, in my testing the True case was actually marginally (probably not significantly) faster in both the min and the average.