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.