×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Apr 2005
    Posts
    75

    Performance od Python

    Hi,

    I am new to Python so I implemented some simple applications to see the performance of Python in comparison to Java and Symbian. Therefore I just programmed some for loops with some simple mathematical operations (subtraction, multiplication) to see the difference to other platforms.

    I was suprised that Python is really slow compared to other languages. Of course, I know, it is interpreted but it is ~15 times slower than java and much more slower than Symbian.

    Is it really that slow or am I doing something wrong?

    Code snippet:

    v1 = [..20 float values]
    v2 = [..20 float values]

    for i in range(100000):
    for j in range(20):
    d = v1[j]-v2[j]
    dd = d*d

  2. #2
    Super Contributor
    Join Date
    Dec 2004
    Posts
    643

    Re: Performance od Python

    Try using xrange instead of range. That may improve performance a little bit. But yes, Python is slower than Java or C++. You should always try to perform mathematical heavy lifting using native modules instead of coding it elementwise in Python.

  3. #3
    Regular Contributor
    Join Date
    Jan 2004
    Location
    Helsinki
    Posts
    376

    Re: Performance od Python

    Quote Originally Posted by Kurt Johannes View Post
    Hi,

    I was suprised that Python is really slow compared to other languages. Of course, I know, it is interpreted but it is ~15 times slower than java and much more slower than Symbian.
    Instead of for loops try use map, filter and other built-in Python mapping operations. They lift the loop iteration to the native code and perform faster.

    If your math code is performance sensitive, move crucial loops to the native C++ extension. This way you get the absolute processor speed, the same as in native C.

    Cheers,
    Mikko
    Mikko Ohtamaa

    http://mfabrik.com
    http://blog.mfabrik.com

Similar Threads

  1. Please help installing Python libraries on S60
    By ericroijen in forum Symbian
    Replies: 11
    Last Post: 2009-07-18, 10:43
  2. [announce] PyUIQ. Python for UIQ 2.1 and 3.x
    By OscarBernabeu in forum Symbian
    Replies: 35
    Last Post: 2008-01-17, 09:12
  3. Replies: 1
    Last Post: 2008-01-08, 09:58
  4. Replies: 11
    Last Post: 2007-10-03, 19:46
  5. Replies: 3
    Last Post: 2007-03-13, 06:50

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •