Get the App
SLTechnology News&Howtos  ›  Development  › 

How to analyze and improve the compiling speed of Chammer Cobb + program

Shulou Source: shulou.com Published: 2022-06-02 19:32:39 09月29日 Update

This article mainly explains the "how to analyze and improve the compilation speed of the Cramming + program". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to analyze and improve the compilation speed of the Cramp Craft + program".

Caused by hardware and compiler

Using a better computer is undoubtedly the best choice for operation. Secondly, compiler options can also be optimized for compilers. For example, in VS environment, you can configure properties. The specific steps are as follows. Please refer to: https://blog.csdn.net/yizhou2010/article/details/52635288

Coding style

Use more self-addition, self-subtraction instructions and compound assignment expressions

Do you think there is any difference between using iTunes +, I = I + 1 and I + = 1? Let's test the C code:

Void asd () {} int main () {int iTun0; iTunes; asd (); / / facilitate context-sensitive ii=i+1; asd (); iTunes 1; return 0;}

Disassembly:

Mov [rbp+i], initialization of call I [rbp+i], 1 rbp+i; call _ Z3asdv; asd (void) add [rbp+i], 1 rbp+i; call _ Z3asdv; asd (void) add [rbp+i], 1//i+=1

We see that the result is the same, but a few more instructions are generated in more complex expressions, and using I + = 1 is always slightly better than writing I = I + 1.

To express division by multiplication or shift.

Division is derived from the process of multiplication, subtracting (if x is enough) y ^ (2 ^ 31), y ^ (2 ^ 30),. Y ^ 8, y ^ 4, y ^ 2, y ^ 1. Subtract the corresponding amount of y and add the corresponding amount to the result. Generally speaking, it takes more time. Test it with a demo.

Auto time_start = std::chrono::system_clock::now (); int iCount = 1000000; double k; for (int I = 0; I < 1000000; iTunes +) {tmp = iCount / 2;} std::chrono::duration time_spend = std::chrono::system_clock::now ()-time_start; double test1 = time_spend.count () * 1000; cout

Tags: Compile function loop variable program code file static object time processing local pointer data type speed global parameter copy time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia OPPO Reno Linux Docker vpn