Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Terry Reedy Newsgroups: comp.lang.python Subject: Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?) Date: Mon, 21 Mar 2016 20:13:01 -0400 Lines: 59 Message-ID: References: <56e44258$0$1598$c3e8da3$5496439d@news.astraweb.com> <8737rvxs89.fsf@elektro.pacujo.net> <56e7483d$0$1608$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de I1At5jCoqFBRfVRnBflBkQ0y/Bz8yh1bBXtv5Dd9frgA== 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; 'elif': 0.04; 'compiler': 0.05; 'python)': 0.05; 'dict': 0.09; 'insertion': 0.09; 'integral': 0.09; 'lookup': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:which': 0.09; 'python': 0.10; 'python.': 0.11; 'jan': 0.11; 'syntax': 0.13; '9:15': 0.16; 'beginning.': 0.16; 'clause.': 0.16; 'clauses': 0.16; 'conditional': 0.16; 'did.': 0.16; 'expressions,': 0.16; 'program?': 0.16; 'python;': 0.16; 're- written': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'recognizing': 0.16; 'reedy': 0.16; "someone's": 0.16; 'subject:?)': 0.16; 'wrote:': 0.16; 'compilation': 0.18; 'instance,': 0.18; 'module,': 0.18; 'test.': 0.18; 'tests': 0.18; '>>>': 0.20; 'claiming': 0.22; 'constant': 0.22; 'parser': 0.22; 'am,': 0.23; 'bit': 0.23; '(or': 0.23; "python's": 0.23; 'this:': 0.23; 'tried': 0.24; 'import': 0.24; 'written': 0.24; 'header:In- Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'external': 0.27; 'define': 0.27; 'equivalent': 0.27; 'order.': 0.27; '---': 0.28; 'towards': 0.28; 'regular': 0.29; 'perl': 0.29; 'code': 0.30; 'task': 0.30; 'regardless': 0.31; 'certain': 0.31; "can't": 0.32; 'core': 0.32; 'included': 0.32; 'optimize': 0.33; '(for': 0.34; 'tasks': 0.35; 'according': 0.36; 'but': 0.36; 'should': 0.36; 'needed': 0.36; 'there': 0.36; 'lines': 0.36; '(and': 0.36; 'faster': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'received:org': 0.37; 'seem': 0.37; 'doing': 0.38; 'several': 0.38; 'test': 0.39; 'whatever': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'decision': 0.61; 'determine': 0.61; 'subject:The': 0.61; 'received:96': 0.63; 'due': 0.65; 'series': 0.65; 'believe': 0.66; 'frequency': 0.66; 'answer.': 0.72; 'overall': 0.72; 'clauses,': 0.84; 'execution.': 0.84; 'received:fios.verizon.net': 0.91; 'placement': 0.95 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: pool-96-227-207-81.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105417 On 3/21/2016 8:34 AM, BartC wrote: > On 21/03/2016 02:21, Terry Reedy wrote: >> On 3/20/2016 9:15 PM, BartC wrote: >>> http://pastebin.com/dtM8WnFZ >>> This is a test of a character-at-a-time task in Python; >> >> I disagree. It tests of C code re-written in ludicrously crippled >> Python. No use of the re module, > > You can't use the re module for this kind of test. It would be like a > writing a C compiler in Python like this: > > system("gcc "+filename) I disagree. The re module is an integral part of python, as delivered, not an external program. It is included (and the core written in C) *because* it is needed to do certain tasks with reasonable speed. Would you say that one cannot use re syntax in a Perl program? The decision to access the functions via syntax rather than import should not determine the answer. > (or whatever the equivalent is in Python) and claiming the compilation > speeds are due to Python's fast byte-code. > >> designed for tasks like this, > > (I've tested someone's parser written in Python using regular > expressions, I seem to remember it was still pretty slow.) I would be flabbergasted is recognizing floats with an re was slower than doing so with several lines of Python, as you did. >> For instance, there are about 15 clauses like >> --- >> elif c=="?": >> lxsymbol=question_sym >> return >> --- >> >> I believe it would be much faster to combine these in one clause. First >> define simple_symbols = {'?': question_sym, ...}. Then >> elif c in simple_symbols: >> lxsymbol = simple_symbols[c] >> return > > I tried that (for 11 clauses), and it actually got a bit slower if the > one test was placed towards the end! But faster if placed nearer the > beginning. I would want to test the dict lookup directly against the equivalent if chain. But the placement issue is one I did not directly address. To optimize a series of conditional clauses, one must order according to frequency of truthfulness and time of execution. Unless one is unlucky, dict lookup should be overall constant regardless of insertion order. -- Terry Jan Reedy