#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    75
    Rep Power
    2

    Why python is slow?


    Why is python slow? How does it work internally? Does it convert the python code to C code first and then assembles it? Is that the reason it is slow?

    In general why are scripting languages slower than compiled languages?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    python compiles source to byte code. The .pyc file is portable for any computer running same version of python. So there you go, python didn't write instructions for native hardware. python interprets the code.

    Python interpreters vary in how they behave. Thus it's possible to write python code that works on some interpreters but not on others. And causes seemingly strange behavior. This caused me some trouble. Not understanding "is", numeric comparisons looked more readable to me using is. Sometimes it worked![code]>>> (100**2) is (100**2)
    False
    >>> (10**2) is (10**2)
    True
    >>> [code]Turns out that some python interpreters cache objects for commonly used integers 0 through 100 making the memory address id(100) constant in these implementations. Portable code must not rely on this feature!

    If you think about it, python spends a lot of time hashing names. Every time you call a function, python doesn't know that "math" still refers to the "math" module. It's got to hash math in math.cos , and it has to hash cos because you might have replaced the function as well. I suppose additional timing would help verify for various ways to express expressions.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480

    Why does slow python interest scientists?


    Developer time is critical, and python has low programming cost. Using the numpy module ( www.enthought.com ) for large arrays the interpreter time becomes negligible, and the array operations take place with direct access in c code. Versus what you might write in a compiled language, numpy might make more copies of an array and get worse cached memory performance, but it's pretty quick.
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    606
    Rep Power
    65
    Interpreted languages like Python and Java are slower than compiled languages like C or C++. However, they have the advantage to work across platforms like Windows or Linux or OSX.

    Speed depends on your program, disk and display access is slow for any language. As hardware gets faster the speed differences are not as noticeable.

    Python allows you to write speed sensitive code in C.
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Location
    chennai
    Posts
    3
    Rep Power
    0

    Why python is slow?


    Because code is interpreted at runtime instead of being compiled to native code at compile time.

    Thank you.

IMN logo majestic logo threadwatch logo seochat tools logo