Why is C so fast

We have heard programmers around us talk about C being fast, so in this article, I’ll be attempting to explain the “why”.

C is fast because… it has no special features. It was designed to be as close to Machine level as possible. The only benefit being that it was readable (I know, I know, just try to imagine assembly devs using C for the first time back then).

Due to how close it is to machine language, the speed of a C program is loosely determined by the number of statements being executed.

From this, we can begin to see that C is not fast per se… other languages are just slow!

And that is because they have a higher level of abstraction to machine language than C does. That is not necessarily a bad thing since higher-level languages (like Python) provide:

  1. Safety checks
  2. Added complexity
  3. Error handling
  4. Memory management
  5. Automatic garbage collection

The only tradeoff being speed… or is it?

is C really the fastest?

Short answer, Not really. Long answer, it is only fast when the programmer writes optimal code. And even then, there are instances where virtual machine-based languages (like Java) run faster than C. Plus, Assembly is a language too and it’s faster than C.

Thanks for reading!

Sources

https://stackoverflow.com/questions/418914/why-is-c-so-fast-and-why-arent-other-languages-as-fast-or-faster
https://www.ibm.com/support/knowledgecenter/zosbasics/com.ibm.zos.zappldev/zappldev_85.htm

原文链接:Why is C so fast

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容