Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'else:': 0.03; 'subject:Python': 0.05; 'modified': 0.05; 'false.': 0.07; 'python': 0.09; 'coding,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'through,': 0.09; '"m"': 0.16; '"python': 0.16; '#python': 0.16; '107': 0.16; '524': 0.16; 'basic.': 0.16; 'corp.': 0.16; 'count,': 0.16; 'n!=1:': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reversing': 0.16; 'subject:3.3': 0.16; 'time.time()': 0.16; 'mon,': 0.16; 'pace': 0.17; 'windows': 0.19; 'app': 0.19; 'feb': 0.19; 'equivalent': 0.20; 'bit': 0.21; 'import': 0.21; '3.x': 0.22; 'runs': 0.22; 'pass': 0.25; 'replace': 0.27; 'header:X -Complaints-To:1': 0.28; 'lines': 0.28; 'run': 0.28; 'coded': 0.29; 'comparison': 0.29; 'surprised': 0.29; 'usually': 0.30; 'basic': 0.30; 'function': 0.30; 'skip:8 10': 0.32; 'print': 0.32; 'url:home': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; '(c)': 0.33; 'project': 0.34; 'built-in': 0.35; 'compared': 0.35; 'false': 0.35; 'there': 0.35; 'received:org': 0.36; 'really': 0.36; 'charset:us-ascii': 0.36; 'bad': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'john': 0.60; 'first': 0.61; 'here': 0.65; 'subject:. ': 0.66; '1980s': 0.84; '2013': 0.84; 'sec.': 0.84; 'subject:Basic': 0.84; 'dennis': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Python 3.3 vs. MSDOS Basic Date: Mon, 18 Feb 2013 19:36:21 -0500 Organization: > Bestiaria Support Staff < References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-253-107-78.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 76 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361234188 news.xs4all.nl 6940 [2001:888:2000:d::a6]:53477 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39147 On Mon, 18 Feb 2013 11:13:04 -0800 (PST), John Immarino declaimed the following in gmane.comp.python.general: > I coded a Python solution for Problem #14 on the Project Euler website. I was very surprised to find that it took 107 sec. to run even though it's a pretty simple program. I also coded an equivalent solution for the problem in the old MSDOS basic. (That's the 16 bit app of 1980s vintage.) It ran in 56 sec. Is there a flaw in my coding, or is Python really this slow in this particular application. MSDOS Basic usually runs at a snails pace compared to Python. > > max=0 "max" is a bad name -- it masks the built-in max() function > m=0 > while m<=1000000: > m+=1 Since "m" is only modified here and has a value of 1 for the first pass through, you can replace those three lines with for m in xrange(1, 1000001): #python 2.x, just use range() for 3.x > count=0 > n=m > while n!=1: > count+=1 > if n%2==0: > n=n//2 > else: > n=3*n+1 Avoid the comparison to 0 by reversing the then/else actions... Any 0 result is false. -=-=-=-=- import time mx = 0 start = time.time() for m in xrange(1, 1000001): count = 0 n = m while n > 1: count += 1 if n % 2: # 0 means false n = 3 * n + 1 else: n = n // 2 if count > mx: mx, num = count, m end = time.time() print num, mx print end-start -=-=-=-=- Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. E:\UserData\Wulfraed\My Documents>cd "Python Progs" E:\UserData\Wulfraed\My Documents\Python Progs>Script1.py 837799 524 83.2030000687 E:\UserData\Wulfraed\My Documents\Python Progs> -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/