[Tutor] Python vs. C

Daniel Ehrenberg littledanehren at yahoo.com
Wed Jan 7 17:59:05 EST 2004


> Hi,
> 
> I was talking with a friend who works as a
> programmer, and I mentioned that 
> I was interested in learning C because it was faster
> than Python. And he 
> asked me why it was faster; and I said because it's
> compiled and Python's 
> interpreted; but he pressed me and I couldn't really
> say why C's being 
> compiled makes it faster. And my friend left me to
> wonder about this: why 
> is it faster? Intuitively, it makes sense to me that
> a language like 
> assembly would be faster because I believe you can
> manipulate the chipset 
> or whatever directly. Is that why C is faster, too?

Yes. In general, lower-level languages are faster.
Although programs like Psyco are trying to break that
(and have already suceeded in making python as fast as
C for simple arithmetic calculations), I don't think
it'll happen anytime soon. However, you can usually
find extentions for Python written in C that increase
the speed of your program without having to resort to
rewriting your program, such as Numeric, a high-speed
list processing library. These programs are very
heavily optimized so they can rival or beat naive
implimentations for involving list processing made by
beginner programmers in C, not to mention that you
don't have to reimpliment everything. If you're not
doing calculation-intensive tasks like manipulating
large lists, you generally can get off writing things
in Python.

> I am wondering about 
> this because my Python programs are getting bigger,
> and occasionally I 
> wonder if I want to learn C too. Plus, I've gotten
> to like programming 
> enough that I learning another language would be
> fun. Or maybe I should 
> just work on making my Python code more efficient or
> whatever? Anyway, if 
> anyone knows the specific details of why C is faster
> or can point me to 
> somewhere I can read about it I'd appreciate it.
> Thanks,
> 
> Peter

There are many large Python programs and most of them
don't have to resort to writing things in C, unless
it's something where speed really matters (like Zope).
Unless you're writing a large database and webserver,
you probably don't need C.

Daniel Ehrenberg 

__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus



More information about the Tutor mailing list