This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
lieudusty's profile picture

Find out how long a program took to run?

Started by lieudusty, 29 October 2012 - 02:02 AM
lieudusty #1
Posted 29 October 2012 - 03:02 AM
Hi everyone! :P/>/>

I'm trying to make something find out how long a program took to run. Does anybody know how to do this?
Lyqyd #2
Posted 29 October 2012 - 03:04 AM
Make a wrapper program. Check os.clock() before you start the other program, check os.clock() after you run it. Simple subtraction gives you the run time.
PixelToast #3
Posted 29 October 2012 - 03:58 AM

local otime=os.clock()
-- code
local timeElapsed=os.clock()-otime
remiX #4
Posted 29 October 2012 - 06:26 PM
Wow loops are fast xD


term.clear() term.setCursorPos(1,1)
BeginTime = os.time()
i = 1
repeat
    i = i + 1
until i == 1000000
print(os.time() - BeginTime)

Results 0.001 :P/>/>
ChunLing #5
Posted 29 October 2012 - 08:30 PM
They're faster than that. It's the world time that's too slow. Use the os.clock, like Lyqyd said. It's more suited to this purpose.