2 – C Opt 01 L V2

Hi, I’m Anthony, the product lead here at Udacity for robotics. You’ve already learned a lot of syntax in C++, including how to write functions and classes. Now you should feel confident that anything you could write in Python, you could also write in C++. But let’s take a step back and talk about why are you learning C++ in the first place. It basically comes down to the fact that certain C++ programs run faster. Autonomous vehicles need to make quick decisions to successfully operate in a dynamic environment. Slicing off fractions of this millisecond from your programs might not seem like a lot, and maybe it isn’t for just one occurrence of an instruction. But self-driving cars execute billions or trillions of instructions in a small amount of time. So those milliseconds add up very quickly. Efficient code is very important if you want your car performing an action when you’re expected to and not seconds later. But how do you get your programs to run faster when using C++? Well, once you have a program that runs correctly, you go through a process called code optimization. Code optimization generally allows your program to use less memory, increase power efficiency, or execute faster. For this lesson, we are going to primarily focus on getting C++ code to execute faster. For almost every line of code you write, the computer will execute a corresponding instruction like writing to or from memory, or running a mathematical calculation. Even something simple like assigning an integer to a variable requires a computer to execute a set of instructions and write to memory. Usually there are multiple ways to write a program and achieve the same results. And if you find a solution that requires fewer instructions for the computer to execute, well then quite simply your code will run faster. We have split this lesson into two parts. First you will get an overview of what is happening inside the computer when you compile and run a C++ program. This will give you some insight into what causes your program to slow down. Then you will take what you’ve learned and use it to optimize C++ code. When you complete this section, you will walk away with the ability as you would say to empathize with the computer.

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