Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58190

Re: Basic Python Questions - Oct. 31, 2013

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <skip.montanaro@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'heavily': 0.04; 'subject:Python': 0.06; 'referring': 0.07; 'subject:Questions': 0.07; 'wrapped': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "(i'm": 0.16; 'basic.': 0.16; 'boundary,': 0.16; 'boundary.': 0.16; 'c++.': 0.16; 'division,': 0.16; 'example)': 0.16; 'exchanges': 0.16; 'firm.': 0.16; 'from:addr:pobox.com': 0.16; 'from:addr:skip': 0.16; 'numpy': 0.16; 'operation.': 0.16; 'python/c': 0.16; 'range,': 0.16; 'range.': 0.16; 'slow,': 0.16; 'underlying': 0.16; 'win,': 0.16; 'sender:addr:gmail.com': 0.17; 'library': 0.18; 'implementing': 0.19; 'written': 0.21; '(the': 0.22; 'cc:addr:python.org': 0.22; 'adds': 0.24; 'skip': 0.24; 'math': 0.24; 'versions': 0.24; 'cc:2**0': 0.24; 'world,': 0.26; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'point': 0.28; 'compared': 0.30; 'sets': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; '$100': 0.31; 'boundary': 0.31; 'operations.': 0.31; 'perl': 0.31; 'yesterday': 0.31; 'handled': 0.32; 'languages': 0.32; 'stuff': 0.32; '(most': 0.33; 'guess': 0.33; 'sense': 0.34; 'could': 0.34; 'operations': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'version': 0.36; 'c++': 0.36; 'doing': 0.36; 'next': 0.36; 'half': 0.37; 'virtual': 0.37; 'so,': 0.37; 'minimum': 0.38; 'depends': 0.38; 'needed': 0.38; 'little': 0.38; 'expensive': 0.39; 'stock': 0.39; 'use.': 0.39; 'how': 0.40; 'up,': 0.60; 'ago,': 0.61; 'lower': 0.61; 'trading': 0.61; 'matter': 0.61; 'simple': 0.61; 'making': 0.63; 'developed': 0.63; 'such': 0.63; 'decided': 0.64; 'more': 0.64; 'within': 0.65; 'here': 0.66; 'subject:. ': 0.67; 'believe': 0.68; 'price': 0.69; 'inline': 0.74; 'price.': 0.74; 'calculations': 0.84; 'relate': 0.84; 'story:': 0.84; 'trades': 0.84; 'time)': 0.91; 'subject:2013': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=mUyaMpigCFslDJRPcMnuG/3Ymeb92u7QrlhgPQdnYwA=; b=aIp+1PFPXlTTAQG+RKW2zOEqyTDDMj4vcNT3une5lcDjGUyd8LOXcB77tVN5BMHgSk PkMfj7QSyRX2TBFtOW8Yozes9C6ttlSBm6TPw1hNc8b9TGyNlK2c3DORbxkIDOwILEU8 PFEpl3jbzmD0Kh4RkB3fSch4gTAD8PYA9s+F5rUCz1h4pHHZzBZCfDFqn7rnncvitIGd ItuchJoJQaPidiAWmwgI4M3nTU1MOOkIpalxkD1pRk+p/KbP7FcoR84uzmWn7A2UZkYn 5jo8/nn7u8MCRdGY0l8DE85e2dQDIfTx5+9+Fsc74NCBrk5uaAnSTWRmbLgz1E9pHNdV dr/Q==
MIME-Version 1.0
X-Received by 10.50.61.205 with SMTP id s13mr79360igr.29.1383236042000; Thu, 31 Oct 2013 09:14:02 -0700 (PDT)
Sender skip.montanaro@gmail.com
In-Reply-To <UdGdnaDGa6n9vu_PnZ2dnUVZ_umdnZ2d@earthlink.com>
References <UdGdnaDGa6n9vu_PnZ2dnUVZ_umdnZ2d@earthlink.com>
Date Thu, 31 Oct 2013 11:14:01 -0500
X-Google-Sender-Auth j9eGI25yDc_7FIpJ7eU8ec-Uxf4
Subject Re: Basic Python Questions - Oct. 31, 2013
From Skip Montanaro <skip@pobox.com>
To "E.D.G." <edgrsprj@ix.netcom.com>
Content-Type text/plain; charset=UTF-8
Cc Python <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1884.1383236045.18130.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1383236045 news.xs4all.nl 15992 [2001:888:2000:d::a6]:37454
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:58190

Show key headers only | View raw


> 1.  How fast can Python do math calculations compared with other languages
> such as Fortran and fast versions of Basic.  I would have to believe that it
> is much faster than Perl for doing math calculations.

As others have indicated, a lot depends on the form of your
calculations. There is a cost to crossing the Python/C boundary, and
you may or may not care about the other stuff Python can do
on-the-fly, like promote ints to Python longs, check for zero
division, etc. If you have floating point code that is array-like,
then organizing it to use numpy can be a big win, as you will cross
that expensive boundary much less often per underlying operation. (I'm
thinking here of more complex operations like trigonometric functions,
not simple adds and subtracts, which are handled by the Python virtual
machine.)

I will relate one anecdote from my job here which highlights the cost
of the boundary. I work at a trading firm. I work solely within a
Python world, but my stuff is built on top of a lot of C++ code
developed by others at the firm. Several years ago, it was decided
that we needed a price library because some exchanges (the London
Stock Exchange, for example) sets the minimum price change based on
the current trading price range. Consider a stock like AAPL, which
closed yesterday at 489.56. It trades in pennies on NASDAQ, no matter
its price. If it was on the LSE, it might trade in half pennies if it
was trading in a $100 range, or in dimes if it was trading near $1000
range. (I'm making this stuff up, just to give you an idea what I'm
referring to.)

So, a price library was written in C++. You could ask for the next
higher or lower valid price. It was all very peppy, because of course,
it relied heavily on C++ inline functions for all these simple
operations. It was wrapped with Boost::Python and tossed over the
fence for us Python peons to use. Guess what? It was unbearably slow,
because not only did we were crossing the Python/C boundary to do
little more (most of the time) than a single add or subtract.

The solution was to write a pure Python version of the parts that mattered most.

Moral of the story: consider how your code is structured and whether
it makes sense to reorganize it when implementing in Python.

Skip

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Basic Python Questions - Oct. 31, 2013 "E.D.G." <edgrsprj@ix.netcom.com> - 2013-10-31 04:31 -0500
  Re: Basic Python Questions - Oct. 31, 2013 Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-10-31 11:03 +0100
    Re: Basic Python Questions - Oct. 31, 2013 "E.D.G." <edgrsprj@ix.netcom.com> - 2013-10-31 05:38 -0500
      Re: Basic Python Questions - Oct. 31, 2013 Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-10-31 12:30 +0100
      Re: Basic Python Questions - Oct. 31, 2013 Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2013-10-31 14:17 +0100
        Re: Basic Python Questions - Oct. 31, 2013 Chris Angelico <rosuav@gmail.com> - 2013-11-01 01:05 +1100
          Re: Basic Python Questions - Oct. 31, 2013 Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2013-10-31 15:18 +0100
            Re: Basic Python Questions - Oct. 31, 2013 Chris Angelico <rosuav@gmail.com> - 2013-11-01 01:45 +1100
        Re: Basic Python Questions - Oct. 31, 2013 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-31 14:15 +0000
          Re: Basic Python Questions - Oct. 31, 2013 Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2013-10-31 15:31 +0100
        Re: Basic Python Questions - Oct. 31, 2013 Robert Kern <robert.kern@gmail.com> - 2013-10-31 14:41 +0000
        Re: Basic Python Questions - Oct. 31, 2013 Chris Angelico <rosuav@gmail.com> - 2013-11-01 01:49 +1100
        Re: Basic Python Questions - Oct. 31, 2013 Robert Kern <robert.kern@gmail.com> - 2013-10-31 15:11 +0000
      Re: Basic Python Questions - Oct. 31, 2013 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-31 13:48 +0000
        Re: Basic Python Questions - Oct. 31, 2013 "E.D.G." <edgrsprj@ix.netcom.com> - 2013-11-03 01:17 -0500
          Re: Basic Python Questions - Oct. 31, 2013 "E.D.G." <edgrsprj@ix.netcom.com> - 2013-11-12 04:21 -0600
            Re: Basic Python Questions - Oct. 31, 2013 Chris Angelico <rosuav@gmail.com> - 2013-11-13 10:05 +1100
      Re: Basic Python Questions - Oct. 31, 2013 rusi <rustompmody@gmail.com> - 2013-10-31 08:48 -0700
        Re: Basic Python Questions - Oct. 31, 2013 "E.D.G." <edgrsprj@ix.netcom.com> - 2013-11-03 00:45 -0500
          Re: Basic Python Questions - Oct. 31, 2013 rusi <rustompmody@gmail.com> - 2013-11-02 23:54 -0700
  Re: Basic Python Questions - Oct. 31, 2013 Roy Smith <roy@panix.com> - 2013-10-31 09:20 -0400
  Re: Basic Python Questions - Oct. 31, 2013 Skip Montanaro <skip@pobox.com> - 2013-10-31 11:14 -0500
  Re: Basic Python Questions - Oct. 31, 2013 William Ray Wing <wrw@mac.com> - 2013-11-01 11:42 -0400
    Re: Basic Python Questions - Oct. 31, 2013 "E.D.G." <edgrsprj@ix.netcom.com> - 2013-11-03 01:28 -0500
  Re: Basic Python Questions - Oct. 31, 2013 Ethan Furman <ethan@stoneleaf.us> - 2013-11-01 11:08 -0700
  Re: Basic Python Questions - Oct. 31, 2013 William Ray Wing <wrw@mac.com> - 2013-11-01 15:17 -0400
  Re: Basic Python Questions - Oct. 31, 2013 "E.D.G." <edgrsprj@ix.netcom.com> - 2013-11-03 01:02 -0500
    Re: Basic Python Questions - Oct. 31, 2013 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-03 07:43 +0000
      Re: Basic Python Questions - Oct. 31, 2013 "E.D.G." <edgrsprj@ix.netcom.com> - 2013-11-03 03:47 -0600
        Re: Basic Python Questions - Oct. 31, 2013 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-03 10:05 +0000
      Re: Basic Python Questions - Oct. 31, 2013 rusi <rustompmody@gmail.com> - 2013-11-03 10:28 -0800
        Re: Basic Python Questions - Oct. 31, 2013 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-03 18:58 +0000
          Re: Basic Python Questions - Oct. 31, 2013 rusi <rustompmody@gmail.com> - 2013-11-03 20:07 -0800
    Re: Basic Python Questions - Oct. 31, 2013 Jim Gibson <JimSGibson@gmail.com> - 2013-11-03 10:18 -0800
      Re: Basic Python Questions - Oct. 31, 2013 Grant Edwards <invalid@invalid.invalid> - 2013-11-03 23:16 +0000
      Re: Basic Python Questions - Oct. 31, 2013 "E.D.G." <edgrsprj@ix.netcom.com> - 2013-11-04 23:22 -0600
        Re: Basic Python Questions - Oct. 31, 2013 88888 Dihedral <dihedral88888@gmail.com> - 2013-11-07 06:05 -0800
  Re: Basic Python Questions - Oct. 31, 2013 sigtool@kcl.ac.uk - 2013-11-10 06:40 -0800

csiph-web