English subtitles

← Predicting Run Time - Intro to Computer Science

Get Embed Code
2 Languages

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.
  23. For your quiz, your goal is to estimate
  24. the expected execution time for a value running spin loop where the input of the
  25. loop is ten star star nine, that's one
  26. billion. And you should give your answer in
  27. the number of seconds. Of course it's not
  28. possible to get the exact answer, but you
  29. should be able to get a guess within about 20% of our answer to be correct.