U
U
Urichat2017-11-26 23:21:00
assembler
Urichat, 2017-11-26 23:21:00

Why are assembly language programs faster?

Friends, I constantly hear that assembler programs work faster than programs in C, C ++, Python, etc. With the latter, everything is clear, the interpreter first translates the code into byte code, then compiles it, and only then executes it. But why is assembler faster, for example, programs in C. It is clear that it can be slower if the hands are crooked. But let's take a spherical programmer in a vacuum who knows exactly what he is doing, writes ideal, fast programs. And now he needs to speed up the program. He decides to write an insertion function in asma in a C program. What will increase the speed of the program? For example, we will assume that it will definitely increase. When we compile the program, the executable file will already be machine code, right? In short, the question from the title is why is this so?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
Decadal, 2017-11-26
@Urichat

Any conversion of a high-level language to machine code incurs overhead. The assembler is faster because the programmer does not write anything extra, and to ensure the universality of the use of language constructs, all machine codes created by translators are redundant.

J
jcmvbkbc, 2017-11-27
@jcmvbkbc

need to speed up the program. He decides to write a nowhere function by inserting in asme in a C program.

No, nifiga is not how programs are optimized. Usually they run a profiler and find the function that takes the most time, analyze it and change the algorithm with exponential complexity to an algorithm with quadratic or linear, and if you're lucky, with constant complexity. without changing the language.

P
pfg21, 2017-11-26
@pfg21

NOT ALWAYS !!
it all depends on the quality of the written code, i.e. pogrom skills. just like in any language.
simple assembler is closest to the binary executable code that is directly executed on the processor.
Accordingly, there is a huge amount of opportunities how to make a code that is ideally suited to a given processor and, accordingly, the fastest. you talk to the prots almost in his language.
but, quite naturally, there are also more options to do shit than in any other language, which requires a lot of knowledge.
a compiler of a higher-level language than an assembler selects the appropriate set of processor instructions for some expression in a high-level language and inserts it into the final executable file. And this selection may not always be perfect.
Plus, the programmer, due to a more variable overview of the entire program, can apply non-standard solutions, popularly called "hacks", which in a given place will work faster or with less resource consumption.

D
devalone, 2017-11-26
@devalone

In theory yes, in practice no. If a person perfectly knows a certain platform and assembler for it, and in general God is in this, then yes, he will write the most efficient program in terms of speed and memory, correctly using the machine instructions of this platform, but in practice there are no such people or very few.

B
Boris Syomov, 2017-11-27
@kotomyava

It's just a myth.
But it, like any other myth, has a basis: complex programs are not written in assembler - it is very time consuming, and simple programs usually work quickly. =)
In fact, theoretically, you can optimize some parts of the code manually and get a better result, not necessarily in speed, by the way, than some high-level language compiler. But modern compilers are good enough, and programmer labor is expensive enough for it to make any sense, even in embedded development.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question