Why is Rust slightly slower than C?
On how &quot;fast&quot; C is, guys, sorry to say this, but in my experience actually (1) even assembler is not very &quot;fast&quot;, (2) for much the same reasons C is not very fast, (3) often Fortran is faster than C, and (4) PL&#x2F;I can be the fastest of all of (1)-(4).  More generally, how Fortran and PL&#x2F;I can be faster than C should be exploited quite generally but apparently has not been fully generally.<p>Why?  How can Fortran and PL&#x2F;I beat assembler and C?<p>In particular, first, Fortran can easily beat C in subroutines that receive multidimensional arrays as parameters.  Here PL&#x2F;I also can beat C for the same reasons.  Second, PL&#x2F;I beats both Fortran and C in string handling.<p>How, why, what the heck is going on?  In simple terms, first, Fortran gets to <i>compile</i> the multidimensional array handling within the language and C does not:  In C, the programmer has to write the array addressing logic (e.g., row major or column major) that looks to the C compiler like just more code where the compiler has to treat that handling as general purpose code; the Fortran compiler KNOWS that the work is array handling and gets to make better uses of registers and to store intermediate results where the Fortran source code can&#x27;t see them and, thus, take some liberties.  That is, in Fortran, the array handling is in the language where the compiler can take liberties where a C compiler has to treat the work as ordinary code and not take the liberties.  PL&#x2F;I has the same advantages.  Second, similarly for string handling in PL&#x2F;I.<p>In particular, commonly in C and Fortran, string handling is via  subroutines that to the linkage editor look like external references that must be linked.  That indirection, stack manipulation, register save, restore, etc., PL&#x2F;I doesn&#x27;t have to do.<p>Scientific, engineering, <i>analytical</i> code is awash in multidimensional arrays, and there Fortran and PL&#x2F;I can beat C.  Now nearly all code is awash in string handling, and there PL&#x2F;I can beat both Fortran and C.<p>For assembler, the old remark was that in practice an assembler programmer would write his own code that was less well designed and, thus, slower than C, Fortran, and PL&#x2F;I.  Further, the assembler programmer would be tempted to have a large library for arrays and strings that would be external subroutine calls likely with the overhead.  Sure, in principle, assembler should win, but in practice writing code good enough to win is usually a bit too much work.<p>More generally, compiled functionality offered directly by the language can be faster than libraries of external subroutines, <i>methods</i>, etc.