From my basic understanding of computer architecture, a computer understands instructions and a computer program written in a high level language is converted to a set of such instructions for the computer to understand.

Also, that given a set of rules are satisfied, any programming language can do what any other can do.

So why is it that a C program is faster than say a program in another language? Why is it not that regardless of the syntax, and features of the language, when converted to a set of instructions in binary, each programming language tries to get a similar result. Thus making each of them more or less as fast as the others, at the expense of say compilation time?

Obviously I'm missing something important here, so what is it?

  • 1
    $\begingroup$ You are missing several textbooks worth of factors. I don't know if that should make you feel better or worse. ;) $\endgroup$
    – Raphael
    Commented Mar 26, 2017 at 11:24
  • 3
    $\begingroup$ Start with accepting that "a C program is faster than say a program in another language" is not a true statement. $\endgroup$
    – Raphael
    Commented Mar 26, 2017 at 11:25
  • $\begingroup$ lol fair enough $\endgroup$
    – Silver
    Commented Mar 26, 2017 at 11:27
  • 1
    $\begingroup$ Since I sometimes want to understand technical things, I wrote a little program that would have taken quadratic space and time in C. (Start with an empty array and an empty string. Repeat n times: Append a character to the string, add a copy of the string to the array. My Mac handled that easily for n = 50,000, using over 1 GB of memory and a few seconds. The same program in Swift took no measurable time and space. At last I tried n = 25,000,000 in Swift and that's when it took about 1.5 GB and 10 or 20 seconds. You need to examine really closely what a language does. $\endgroup$
    – gnasher729
    Commented Mar 26, 2017 at 12:13
  • $\begingroup$ not necessarily true, but roughly more language features == more boilerplate code at machine level == bigger lag $\endgroup$ Commented Feb 18, 2019 at 14:11