Answer the question
In order to leave comments, you need to log in
Why are the speeds of different languages different?
Why do all languages have different speed if they translate everything into binary code? Even if we take, for example, two almost identical lines of code from different languages, will they still be different in binary?
Answer the question
In order to leave comments, you need to log in
Let's say we need to add two numbers - 2 and 3
In assembler:
Put 2 in the ax register, 3 - in the bx register, execute the register addition command - as a result, we have the answer in ax.
Roughly speaking, we have executed only 3 commands at the processor level.
In C:
Stored register values, made initializations, performed 3 previous addition commands - restored register values. We have already spent at least a few commands more on registers / initialization.
Some high-level language with dynamic typing:
Take a variable and convert it to a number. They took the second variable - converted it into a number. They called a certain class that can add integers, floating point numbers, concatenate strings, etc. Passed these two of our variables. In addition to the actual addition of numbers, explicit and implicit conversions are performed, checks for exceptions are performed, class methods that can do many operations are called, and so on, initial initializations, on-the-fly optimizations, register saving, etc. are performed ...
That is, for the task of folding numbers, an order of magnitude more processor instructions are already used.
same lines of code from different languages
Will they still be different in binary?
curvature and flaws in code optimization.
or vice versa, the troubles of the layers of protection of iron from the user / pogromist.
lines can be generally identical 1 to 1, but in different languages the compiler can process them differently, therefore, the machine code will be different
Binary code is different. There is assembler code, it is also binary, and there is the so-called "byte code" - created for some kind of runtime runtime environment.
Assembly code is always faster than any runtime execution.
You can clearly see it here https://godbolt.org
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question