Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance of compiled code by compiled compiler

If I want to achieve better performance from, let's say for example, MySQLdb, I can compile it myself and I will get better performance because it's not compiled on i386, i486 or what ever, just on my CPU. Further I can choose the compile options and so on... Now, I was wondering if this is true also for non-regular Software, such as compiler. Here come the 1st part:

  • Will compiling a compiler like GCC result in better performance? and the 2nd part:
  • Will the code compiled by my own compiled compiler perform better?

(Yes, I know, I can compile my compiler and benchmark it... but maybe ... someone already knows the answer, and will share it with us =)

like image 842
oz123 Avatar asked Jan 23 '12 13:01

oz123


People also ask

How much faster is compiled code?

Compiled code runs at least one order of magnitude faster than interpreted code. I base this opinion on a previous experience comparing the performance of Java code before and after the JIT has compiled the byte code. I have found the relation to be approximatelly 30 to 1.

Does compiled code run faster?

Compiled languages are converted directly into machine code that the processor can execute. As a result, they tend to be faster and more efficient to execute than interpreted languages. They also give the developer more control over hardware aspects, like memory management and CPU usage.

How much faster is compiled Python?

It's worth noting that while running a compiled script has a faster startup time (as it doesn't need to be compiled), it doesn't run any faster. It's worth noting that while running a compiled script has a faster startup time (as it doesn't need to be compiled), it doesn't run any faster. A common misconception.

How JIT compiler improves the performance?

The JIT compiler helps improve the performance of Java programs by compiling bytecodes into native machine code at run time. The JIT compiler is enabled by default. When a method has been compiled, the JVM calls the compiled code of that method directly instead of interpreting it.


3 Answers

In answer to your first question, almost certainly yes. Binary versions of gcc will be the "lowest common denominator" and, if you compile them with special flags more appropriate to your system, it will most likely be faster.

As to your second question, no.

The output of the compiler will be the same regardless of how you've optimised it (unless it's buggy, of course).

In other words, even if you totally stuffed up your compiler flags when compiling gcc, to the point where your particular compiled version of gcc takes a week and a half to compile "Hello World", the actual "Hello World" executable should be identical to the one produced by the "lowest common denominator" gcc (if you use the same flags).

like image 183
paxdiablo Avatar answered Nov 13 '22 06:11

paxdiablo


(1) It is possible. If you introduce a new optimization to your compiler, and re-compile it with this optimization included - it is possible that the re-compiled code will perform better.

(2) No!!!! A compiler cannot change the logic of the code! In your case, the logic of the code is the native code produced at the end. So, if compiler A_1 is compiled using compiler A_2 or B, has no affect on the native code produced by A_1 [in here A_1, A_2 are the same compilers, the index is just for clarity].

like image 21
amit Avatar answered Nov 13 '22 04:11

amit


a.Well, you can compile the compiler to your system, and maybe it will run faster. like any program. (I think that usualy it's not worth it, but do whatever you want).

b. No. Even if you compile the compiler in your computer, it's behavior should not change, and so the code that it generates also doesn't change.

like image 42
asaelr Avatar answered Nov 13 '22 05:11

asaelr