[Tutor] Python vs. C

Marilyn Davis marilyn at deliberate.com
Wed Jan 7 02:16:25 EST 2004


On Tue, 6 Jan 2004, Peter Jakubowicz wrote:

> 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 

Hi,

Besides being completely compiled and so quick to run, C does not have
dynamic typing -- which means that the programmer has to decide whether
each variable will be an integer, or a floating point number, or whatever.

Python does this automatically but there is runtime overhead involved
in figuring that out for each variable and so it runs more slowly.

Also, Python handles dynamic memory allocation automatically.  In C,
when you want some memory, the programmer has to ask for it explicitly 
while Python figures it all out at runtime -- making it slower.

These are the reasons I'm aware of.  C is harder for the programmer, but
faster at runtime.  It is a rewarding language too, my other favorite.

> assembly would be faster because I believe you can manipulate the chipset 

Well!  I have heard that sometimes C is faster than assembler because
the language invites more efficiency in the coding.

That's all I know.

Yes, learn C!  It's interesting and powerful.

Marilyn Davis

> or whatever directly. Is that why C is faster, too? 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
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 





More information about the Tutor mailing list