A note about Compilers and their speed

I learnt an interesting new thing today about compilers which I want to share on this blog. I had heard most people say, and also believed that Python is a slow language, meaning it’s compiler is slow. But is it really so?

Are compilers slow and fast? What really affects the speed of execution of code in a particular language?

The answer is that the process of compilation has nothing to do with the running time of a code. Compilation merely involves the generation of Machine Code, which the computer understands from the object code. Running time is the execution of that Machine Code. No matter how slow the process of generation of a machine code is, the execution of the code will depend upon exactly how optimised the machine code is.

By that logic, a compiler written in Python might outperform a compiler written in C. It’s because the output of the compiler (or compilation) doesn’t depend on the language it’s written in, but the algorithms and the optimizations used by it. You could write a really slow, inefficient compiler that produces very efficient code. There’s nothing very special about a compiler, except it’s made of lexical analysers and other stuff, and it’s work in a nutshell is to take some input and produce some output.

Source: How can a language whose compiler is written in C ever be faster than C?

Can a dynamic language like Ruby/Python reach C/C++ like performance?



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s