Difference between revisions of "Os.clock"

From ComputerCraft Wiki
Jump to: navigation, search
(Anh chau Ta cung nhau nhin di)
(Better coding habits and better example)
 
(9 intermediate revisions by 7 users not shown)
Line 1: Line 1:
Hello my friend heres my new gig easy as it looks Ill send u a total of 5350++ backlinks to your website in 2 tiers. This gig its for 1 website and up to 5 keywords. First tier to your main website 350 page rank 1-5 and the the second tier of 5000 profile backlinks pointing to your first tier.Ill send u a report in a txt file in less than 48 hours.Any question just send me a private message
+
{{lowercase}}
 +
{{Function
 +
|name=os.clock
 +
|returns={{type|number}}, amount of time the computercraft computer has been running, in seconds.
 +
|api=OS
 +
|addon=ComputerCraft
 +
|desc=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.
 +
|examples=
 +
{{Example
 +
|desc=Measure how long a task takes to complete
 +
|code=local function consumeTime()
 +
  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]]

Latest revision as of 08:31, 6 November 2013


Grid Redstone.png  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

Examples

Grid paper.png  Example
Measure how long a task takes to complete
Code
local function consumeTime()
  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