Difference between revisions of "Os.clock"
From ComputerCraft Wiki
m |
(Better coding habits and better example) |
||
Line 8: | Line 8: | ||
|examples= | |examples= | ||
{{Example | {{Example | ||
− | |desc=Measure how long a | + | |desc=Measure how long a task takes to complete |
− | |code= | + | |code=local function consumeTime() |
− | |output=Time it took to run | + | sleep(4) |
+ | end | ||
+ | |||
+ | local startTime = os.clock() -- before we do anything | ||
+ | consumeTime() -- perform the action you wish to time | ||
+ | local endTime = os.clock() -- we now get the time again | ||
+ | local difference = endTime - startTime -- the time it took is the end minus the start | ||
+ | print("Took "..difference) | ||
+ | |output=Time it took to run the tasks, in this case 4 seconds | ||
}} | }} | ||
}} | }} | ||
[[Category:Lua_Core_Functions]] | [[Category:Lua_Core_Functions]] |
Latest revision as of 08:31, 6 November 2013
Function os.clock | |
Returns the amount of time the Computer has been running, note that this may not be the amount of time the program has been running. the function os.clock() is useful for debugging, see the example. | |
Syntax | os.clock() |
Returns | number, amount of time the computercraft computer has been running, in seconds. |
Part of | ComputerCraft |
API | OS |