Re: question on time( )

new topic     » goto parent     » topic index » view thread      » older message » newer message

mexzony, please stop spamming the forum. You do not have to post a question multiple times. Be patient and wait for an answer.

mexzony said...

cant quite understand fully how the time function is used.for example look at this code

constant ITERATIONS = 1000000 
integer p 
atom t0, loop_overhead 
 
t0 = time()---line 1 
for i = 1 to ITERATIONS do 
    -- time an empty loop 
end for 
loop_overhead = time() - t0--- line 2 
 
t0 = time()--line 3 
for i = 1 to ITERATIONS do 
    p = power(2, 20) 
end for 
? (time() - t0 - loop_overhead)/ITERATIONS--- line 4 
-- calculates time (in seconds) for one call to power 

time() is assigned to t0 and yet time() - t0 is assigned to loop_overhead and then the last line says ? (time() - t0 - loop_overhead)/ITERATIONS.now my confusion is what will be the values of t0 in line 1,in line 2 the value of time() and in line 3 the value of t0 again and finally the individual values of time(),t0,loop_overhead.i just need some clarification.my head is so hot right now i cant quite seem to think well.i just need someone to explain the whole code if you can.thanks a lot guys

I'm guessing you're fairly new to programming.

The time() function returns the number of seconds since the program started.

So therefore t0 = time() assigns a number of seconds to t0. In other words, it saves the current 'time'. Later the loop_overhead is calculated as the difference between the time the empty loop ended and the time it started. Thus giving you the number of seconds recuired to just run an empty loop. Later another loop is run but this is not empty. The coder wants to find out how much time it takes to the the power() function.

So it calculates the time it takes for a loop plus the power() function then subtracts the time it takes for an empty loop.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu