
Title:
Spin Loop  Intro to Computer Science

Description:

So, to get a better sense of how timing works,

I've defined a procedure spin loop. Spin loop starts by

initializing the variable i to zero and then it goes

through a loop n times, each time through the loop is

just adds one to i. So that'll run for longer,

we can, by picking the value of n, make it

go through the loop any number of times. So, let's

try that. So I'll try running the loop 1,000 times and

now we get no result, and the time it took is 0.0001 seconds. So, about a tenth

of a millisecond. Let's try it with a

larger number of executions, so now I am going

to increase the number of iterations by ten,

so the value of n's multiplied by ten. And

if we see that now, the time is, is higher, the time is increased to about six

tenths of a millisecond and we can keep increasing

the time, so let's try looping 100,000 times. And

we see if the time increases. And the time

increased by about a factor of ten. Between looping

10,000 times and looping 100,000 times. And we'll try

one more time. Let's go for a million. If

we go for a million times, now we're up

to 0.05. So, five hundredths of a second, or

55 milliseconds. To loop a million times. Still pretty fast, right? We're going

through that loop a million times. It's still much less than a second.

What's important is, we can see that well, the time changes depending on

the input. As we increase the input

to spin loop, the time increases accordingly.