470,647 Members | 1,219 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

How to make python run faster

I read this article on http://kortis.to/radix/python_ext/

And I decided to try if it's true.

I write the program in 4 ways:

1. Pure C
2. Python using C extension
3. Python using psycho
4. Pure Python

And then I used timeit to test the speed of these 4. Unsurprisingly,
the time they cost were:

4 3 2 1

But I did noticed that 2 is a least 3 times slower than 1, not as fast
as the article stated.

That's quite weird and I thought maybe it's because I am using
Windows. I did the same test on Linux and I found 2 only uses 1.5
times of time of 1.

But, it is still not as fast as 1.
Jun 27 '08 #1
2 2658
On Apr 14, 8:48 am, һʫ <newpt...@gmail.comwrote:
But, it is still not as fast as 1.

So if speed is the #1 design goal, use pure C. If not, develop in
pure Python and, if the application is too slow, profile the code and
look for bottlenecks that can be optimized. There's a good chance
that they can be resolved algorithmically, not by simply dropping down
to C.
Jun 27 '08 #2
On 14 Ц, 16:48, һʫ <newpt...@gmail.comwrote:
I read this article onhttp://kortis.to/radix/python_ext/

And I decided to try if it's true.

I write the program in 4 ways:

1. Pure C
2. Python using C extension
3. Python using psycho
4. Pure Python

And then I used timeit to test the speed of these 4. Unsurprisingly,
the time they cost were:

4 3 2 1

But I did noticed that 2 is a least 3 times slower than 1, not as fast
as the article stated.

That's quite weird and I thought maybe it's because I am using
Windows. I did the same test on Linux and I found 2 only uses 1.5
times of time of 1.

But, it is still not as fast as 1.
I have experimented too with this scenario. My conclusion is that it
aint worth it to mess with C. Program only in Python and when the time
comes that you want to speed up something, just use Psyco on this. And
that will be more than enough.
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

54 posts views Thread by Brandon J. Van Every | last post: by
38 posts views Thread by kbass | last post: by
36 posts views Thread by Armin Rigo | last post: by
15 posts views Thread by Duncan Lissett | last post: by
14 posts views Thread by Wolfgang Keller | last post: by
11 posts views Thread by Wilk | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
7 posts views Thread by Steve Bergman | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.