7 – C Opt 05 L V3

At this point, you have seen how inefficient code can cause your program to slow down by performing unnecessary CPU operations and memory accesses. Next, we will discuss the practicalities of optimizing your code. Code optimization is a big topic that involves analyzing algorithms, understanding how a computer executes instructions, and learning the nuances of both the programming language and the compiler you were using. Code efficiency also depends on the compiler and the hardware you’re utilizing. Many compilers will try to optimize code for you, and different compilers might optimize in different ways. Code that works well in one case might not work efficiently in another application. And once CPU architectures instruction set, might have instructions to perform an operation very efficiently while another may not. Therefore, you cannot rely only on instinct when optimizing code. You need to test your code and find places that put high demand on your CPU. Whether that be related to time, memory usage, or power consumption. And then any changes you make to your code need to be tested to make sure everything actually runs more efficiently as you expected it to. Next, you will get a chance to optimize the C++ histogram filter. You might remember from the introductory C++ lessons, when Andy showed Elisia his code. Andy had translated his Python histogram filter code into C++. Elisia had brought up that his code had a few inefficiencies. We’re providing you with the inefficient code and your task is to make it run as fast as you can.

%d 블로거가 이것을 좋아합니다: