Optimized Execution Time

Because of a school assignment I have to convert a C++ code to assembly(ARMv8). Then I have to compile the C++ code using GCC's -O0,-O1,-O2,-O3 and -Os optimizations, write down the time and compare with the execute time of my assembly code. As, I think I know -O3 have to be faster than -O1 and -O2. However, I get that -O2 is the fastest, then are -O1,-O3,-Os,-O0. Is that usual? (Calculated times are about 30 seconds).


Yes, it is usual. Take the -Ox optimization as guide-lines. In average, they produce optimization that is advertise, but a lot depends on the style in which the code is written, memory layout, as well as the compiler itself. Sometimes, you need to try and fail many times before getting the optimal code. -O2 indeed gives the best optimization in most of the cases.


Notice that GCC has many other optimization flags.

There is no guarantee that -O3 gives faster code than -O2 ; a compiler can apply more optimization passes, but they are all heuristics and might be unsuccessful (or even slow down slightly your particular code). Hence it does happen that -O3 gives some slightly slower code than -O2 (on some particular input source code).

You could try a more recent version of GCC (the latest -in November 2017- is GCC 7, GCC 8 will go out in few months). You could also try some better -march= or -mtune= option.

At last, with your GCC plugin, you might add your own optimization pass, or change the order (and the set) of applied optimization passes (there are several hundreds different optimization passes in GCC). But you'll need a lot of work (perhaps a year or two) to be able to extend GCC.

You could tune optimization parameters, and some project (MILEPOST) has even used machine learning techniques to improve them.

See also slides and references on my (old) GCC MELT documentation.

链接地址: http://www.djcxy.com/p/40882.html

上一篇: CLP(FD)的相互排斥

下一篇: 优化的执行时间