Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #58180
| References | (1 earlier) <mailman.1868.1383213790.18130.python-list@python.org> <zOOdnQo2GfCgru_PnZ2dnUVZ_rWdnZ2d@earthlink.com> <877gctd1fn.fsf@dpt-info.u-strasbg.fr> <CAPTjJmownGpi3CDpndp5d2gh91=e-Qadc9GxuK+uXot++K7iKQ@mail.gmail.com> <l4tq6a$v14$1@ger.gmane.org> |
|---|---|
| Date | 2013-11-01 01:49 +1100 |
| Subject | Re: Basic Python Questions - Oct. 31, 2013 |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1879.1383230996.18130.python-list@python.org> (permalink) |
On Fri, Nov 1, 2013 at 1:41 AM, Robert Kern <robert.kern@gmail.com> wrote: > On 2013-10-31 14:05, Chris Angelico wrote: >> >> On Fri, Nov 1, 2013 at 12:17 AM, Alain Ketterlin >> <alain@dpt-info.u-strasbg.fr> wrote: >>> >>> "E.D.G." <edgrsprj@ix.netcom.com> 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. Of course that's true, but that difference is just as much whether you're working with addition or trig functions. That overhead is the same. So if, as I said in the other post, you're doing some heavy crypto work or something, then yes, all that boxing and unboxing is expensive. Most programs aren't doing that, so the advantage is far less (by proportion). Plus, high level languages like Python make it a *LOT* easier to work with arbitrary-precision integers than C does. In Python, you just work with the default integer type and it's infinite-precision. In C, you have to switch to explicitly using GMP (or equivalent). I'd much rather pay the overhead and have the convenience of int being able to store any integer. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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