Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'cpython': 0.05; 'subject:Python': 0.06; 'c++,': 0.07; 'perl,': 0.07; 'subject:Questions': 0.07; 'alain': 0.09; 'arrays': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'instruction,': 0.16; 'kern': 0.16; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'underlying': 0.16; 'do,': 0.16; 'language': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'interpret': 0.24; 'pointer': 0.24; 'math': 0.24; 'question': 0.24; 'compiled': 0.26; 'push': 0.26; 'gets': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'rest': 0.29; 'chris': 0.29; 'am,': 0.29; "doesn't": 0.30; '(like': 0.30; 'robert': 0.30; "i'm": 0.30; 'that.': 0.31; 'bunch': 0.31; 'libraries': 0.31; 'once,': 0.31; 'overhead': 0.31; 'writes:': 0.31; 'probably': 0.32; 'fri,': 0.33; "i'd": 0.34; 'but': 0.35; 'functions.': 0.36; 'in.': 0.36; 'implement': 0.38; 'arrange': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'anything': 0.39; 'does': 0.39; 'expensive': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'then,': 0.60; 'most': 0.60; 'hardware': 0.61; 'simple': 0.61; "you're": 0.61; 'such': 0.63; 'our': 0.64; 'more': 0.64; 'relatively': 0.65; 'world': 0.66; 'subject:. ': 0.67; 'believe': 0.68; 'calculations': 0.84; 'difference.': 0.84; 'eco': 0.84; 'terrible': 0.84; 'trig': 0.84; 'boxes': 0.91; 'subject:2013': 0.95; 'you).': 0.95; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: Basic Python Questions - Oct. 31, 2013 Date: Thu, 31 Oct 2013 14:41:24 +0000 References: <877gctd1fn.fsf@dpt-info.u-strasbg.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 213.1.240.226 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 In-Reply-To: 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383230505 news.xs4all.nl 15869 [2001:888:2000:d::a6]:34027 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:58177 On 2013-10-31 14:05, Chris Angelico wrote: > On Fri, Nov 1, 2013 at 12:17 AM, Alain Ketterlin > wrote: >> "E.D.G." writes: >> >>> The calculation speed question just involves relatively simple >>> math such as multiplications and divisions and trig calculations such >>> as sin and tan etc. >> >> These are not "simple" computations. >> >> Any compiled language (Fortran, C, C++, typically) will probably go much >> faster than any interpreted/bytecode-based language (like python or >> perl, anything that does not use a jit). > > Well, they may not be simple to do, but chances are you can push the > work down to the CPU/FPU on most modern hardware - that is, if you're > working with IEEE floating point, which I'm pretty sure CPython always > does; not sure about other Pythons. No need to actually calculate trig > functions unless you need arbitrary precision (and even then, I'd bet > the GMP libraries have that all sewn up for you). So the language > doesn't make a lot of difference. Sure it does. Python boxes floats into a PyObject structure. Both Python and C will ultimately implement the arithmetic of "a + b" with an FADD instruction, but Python will do a bunch of pointer dereferencing, hash lookups, and function calls before it gets down to that. All of that overhead typically outweighs the floating point computations down at the bottom, even for the more expensive trig functions. This is where numpy comes in. If you can arrange your computation on arrays, then only the arrays need to be unboxed once, then the rest of the arithmetic happens in C. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco