Search code examples
cperformance

Why is C so fast, and why aren't other languages as fast or faster?


In listening to the Stack Overflow podcast, the jab keeps coming up that "real programmers" write in C, and that C is so much faster because it's "close to the machine." Leaving the former assertion for another post, what is special about C that allows it to be faster than other languages?

Or put another way: what's to stop other languages from being able to compile down to binary that runs every bit as fast as C?


Solution

  • There isn't much that's special about C. That's one of the reasons why it's fast.

    Newer languages which have support for garbage collection, dynamic typing and other facilities which make it easier for the programmer to write programs.

    The catch is, there is additional processing overhead which will degrade the performance of the application. C doesn't have any of that, which means that there is no overhead, but that means that the programmer needs to be able to allocate memory and free them to prevent memory leaks, and must deal with static typing of variables.

    That said, many languages and platforms, such as Java (with its Java Virtual Machine) and .NET (with its Common Language Runtime) have improved performance over the years with advents such as just-in-time compilation which produces native machine code from bytecode to achieve higher performance.