From: Ari H. <ahe...@an...> - 2001-04-23 17:54:42
|
On Mon, Apr 23, 2001 at 12:59:15PM +0200, Markus Gritsch wrote: > Delphi trys to optimize the code at compile time. It recognizes, that > there is really nothing to do, so the whole loop construct is optimized > away. > > C++ would probably be as fast as Delphi if you compile with -O3 or > something like this. Both quite true. But there does remain an issue of speed when there *is* actual computation in the loop. > > Python does no optimizations, so Python is really performing the loops, > even if there is nothing to do. So in a real world example there would of > course be something to do in the inner loop, so Delphi and C++ won't return > emmediate. The other point is that Python is interpreted (even if the > script is translated to bytecode before), and scripting languages tend to > be 20 to 30 times slower than compiled ones. But if you want short > turn-around times, and want to have fun during programming, ... > Python is a *very* slow language. The way to do this efficiently is with the Numeric package, which allows you to treat multidimensional arrays as primitive datatypes. In general, operations using Numeric can be within a factor of 2 or 3 of C (that is darn fast, especially considering that Python is one of the slowest languages around). There is an excellent Numeric tutorial at http://starship.python.net/~da/numtut/array.html ari |