## ← Predicting Run Time - Intro to Computer Science

• 2 Followers
• 29 Lines

### Get Embed Code x Embed video Use the following code to embed this video. See our usage guide for more details on embedding. Paste this in your document somewhere (closest to the closing body tag is preferable): ```<script type="text/javascript" src='https://amara.org/embedder-iframe'></script> ``` Paste this inside your HTML body, where you want to include the widget: ```<div class="amara-embed" data-url="http://www.youtube.com/watch?v=P8FEHCpnVp8" data-team="udacity"></div> ``` 2 Languages

• English [en] original
• Japanese [ja]

Showing Revision 5 created 05/25/2016 by Udacity Robot.

1. This quiz will see if you understand execution time
2. well enough to make some predictions. So, here's the
3. code we had before that times the execution of
4. evaluating a Python expression that we pass in as
5. code. And we've defined spin loop as a y
6. loop that goes through a loop that just adds
7. one the number of times of the variable passed
8. in. So let's try that in the Python interpreter.
9. We're going to time an execution where
10. what we're evaluating is calling spin loop, passing
11. in some numbers. So we'll try 1,000 first.
12. And what time execution does is return two
13. values. The result and the run time. We only want the second one, so we'll index
14. to get the second value out of the return result, and see that result. So that's
15. what we get, so it took 0.0001 seconds to do spin loop a thousand. If I increase
16. this to 10,000, I see that it takes 0.0006. Lets try 100,000,
17. adding one more zero and I see now it takes 0.005. I'm going to write this a
18. little differently, so we can see it more easily. So now, instead of writing
19. out a 100,000, I'll do ten star, star, five, which is the same value as writing
20. out a one followed by five zeros. And for good measure, we'll do ten star, star,
21. six, which is a million times through the loop, and we see that, that takes 0.05
22. seconds. So here's the examples of timing loops.