WebPython: Testing... Why is the speed of Python Slow ?

Don't know if this is an inherent design flaw or not. But, Python is very slow for some reason. In all my tests with just writes to stdout I noticed that the "Waiting" time is significant.

Here's is an image to prove my point:

I have used FastCGI correctly, but the waiting time is just annoying. What could be the reason ?

One of things I learned about the Python programming language is that it makes use of dictionaries for everything. It obviously uses hash functions but its still quite slow. My question here is that, is there a limit on the size of the dictionary ? And, what happens when collisions happen, how does it then identify the correct key-value pair ? What is the Hash Key size, as in how may bits is it ?

I guess I will have to try and find out a way to understand the Python Dictionary implementation. Maybe even improve it if at all it is possible.

The other thing I noticed is that, when importing a package, python has to parse throught __init__.py and the associated set of files in that package. Does accessing these files cause a problem ?

Time to run some tests...

Waiting time for a 128x128 PNG is 32 msec

Waiting time for this test is 35msec, in this test what I am doing is printing using OS module instead of sys module, the performance is almost similar, but here the waiting time has reduced but the transfer time has increased. Also I am printing it >1000 times by repeating the os.write statement unlike the first test shown in this post where i am using sys.stdout.write.

This test was similar to the previous except that in the previous test I converted a string to bytes once and printed it > 1000 times, in this case I am converting for each and everytime. Naturally, it is slower.

In this test I am still using os.write with bytes, string converted to bytes once, but the print happens in a for loop. And, Naturally it is faster than the previous two tests. The waiting time dropped to 21msec, but the transfer time remains bad in comparison to the first test in the post.

Here I guess we can safely assume that it takes a minimum of 20msec for the python interpreter to start sending out the first byte.

Maybe, incorporating Fast-CGI in to default python interpreter which calls Py_Main function is infact making it slow, as opposed to using the interpreter library and calling Py_Simple... Functions. As the former does a lot of job like parsing command line arguments etc.

Time to do some more tests...

Comments

Popular Posts