The fastest executable code?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
6 views
Do you think/know how at the moment the language/compiler make the productive code.

Does it depend on the tasks performed by this code.

Is it true that modern C++ compilers optimize the code so that it turns faster than if I would to write Assembly code.
by | 6 views

7 Answers

0 like 0 dislike
The fastest executable code is the one written by a sane programmer. If you have code vypolnyaetsya in O(nn), although there is an algorithm that makes the same O(n), you no the compiler will not help.
\r
And good results give Studio compilers and GCC. Well, Intel C++, although it should be ticate that the resulting binary does not tupil on the AMDшных percent.
\r
Something like this.
\r
Regarding optimizations — the compiler knows about the alignment, a conveyor and a bunch of different things, even at the expense in the right place stuck NOP will speed up the code in several times.
by
0 like 0 dislike
The fastest code is the one that fails )
by
0 like 0 dislike
Quote Lugovskogo:
\r
A person can not really effective to write on the assembler.
\r
In the process of compiling a high-level designs (even only arithmetic expressions) there are several steps that require either the use of a large number of clever heuristics, or NP-hard enumeration or dynamic programming.
\r
This applies particularly to such a curve the platform as x86: registers a little, everyone has their quirks, plavecka x87 — all the nightmare on elm street — Polyakova-preregistrant machine with a bunch of difficult to explain the conventions. Smart the compiler theoretically, any reasonably sophisticated algorithm can produce better code than it does people. The fact that not all compilers are smart — that is another question. But in most cases it is more reasonable to write a custom compiler to write in assembler directly.
\r
by
0 like 0 dislike
I doubt that the C++ compiler can do better code than code written in assembler. After all, the approach the Assembly language programmer is always unique.
by
0 like 0 dislike
Technically, the fastest code for a particular CPU, you can write in machine code. Especially when you consider ALL the hardware peculiarities of particular machines on which this code runs. However, this code in most cases will not be portable. In General on this subject should read the book Kaspersky K. — "Engineering optimization programs. Efficient use of memory".
There are comparative tests of compilers.
by
0 like 0 dislike
Man produces faster code. Compilers actually don't know anything about conveyors and rightly so — they are very different on different processors, so optimizing for one will worsen the speed on the other. Just insert NOP'ov demonstrates this. A function can be accelerated by 5-10%, so why the compiler didn't insert nop this?! All they do is align the loops. This work is easy automatiseret macros.
\r
When talking about the NP-completeness of program optimization and compiler to sort out the many options people completely forget about that man and computer are playing by different rules — the person is not limited to the source program, and can do optimizations that the compiler is prohibited (for example, a person can know that certain pointers are not aliases during normal operation of the program; turn the cycle because the specification stated that the procedure for issuing results is not important) or to use designs that are not in the programming language (simultaneous division and obtaining the remainder multiplying 32-bit integers with 64-bit result). And the more complex the algorithm, the greater the number of cases in humans compared to a compiler.
\r
It should be noted that knowing how the algorithm will look best at a low level, it is possible to help the compiler, making optimizations are prohibited for him. Usually this can even add optimization, which the compiler does not know or does not consider it necessary to use (trying to make the code smaller for example). As a result, in many cases it turns out the code comparable with Assembly language, but this merit is not of the compiler.
by
0 like 0 dislike
The fastest code is the one that is executed at compile time.
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
28,000 users