mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 09:46:53 -04:00
give /bin/time much better output using uptime, big thanks to gamax92
This commit is contained in:
parent
8087d6523a
commit
cbf676435c
@ -1,22 +1,18 @@
|
|||||||
|
local computer = require('computer')
|
||||||
local sh = require('sh')
|
local sh = require('sh')
|
||||||
|
|
||||||
local clock_before = os.clock()
|
local real_before, cpu_before = computer.uptime(), os.clock()
|
||||||
local cmd_result = 0
|
local cmd_result = 0
|
||||||
if ... then
|
if ... then
|
||||||
sh.execute(nil, ...)
|
sh.execute(nil, ...)
|
||||||
cmd_result = sh.getLastExitCode()
|
cmd_result = sh.getLastExitCode()
|
||||||
end
|
end
|
||||||
|
local real_after, cpu_after = computer.uptime(), os.clock()
|
||||||
|
|
||||||
local clock_after = os.clock()
|
local real_diff = real_after - real_before
|
||||||
local clock_diff = clock_after - clock_before
|
local cpu_diff = cpu_after - cpu_before
|
||||||
|
|
||||||
-- format time
|
print(string.format('real%5dm%.3fs', math.floor(real_diff/60), real_diff%60))
|
||||||
local minutes = clock_diff / 60
|
print(string.format('cpu %5dm%.3fs', math.floor(cpu_diff/60), cpu_diff%60))
|
||||||
local seconds = clock_diff % 60
|
|
||||||
|
|
||||||
local seconds_txt = string.format('%f', seconds)
|
|
||||||
seconds_txt = seconds_txt:gsub('^(.*%....).*$','%1')
|
|
||||||
|
|
||||||
io.write(string.format('\nreal%5dm%ss\n', minutes, seconds_txt))
|
|
||||||
|
|
||||||
return cmd_result
|
return cmd_result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user