debug lines, timing improved/corrected
This commit is contained in:
+22
-8
@@ -1,18 +1,26 @@
|
||||
local timing = {}
|
||||
|
||||
local function human_readable_time(delta)
|
||||
if delta >= 2*7*24*60*60 then -- if more than 2 weeks
|
||||
delta = tostring(math.floor(delta/(7*24*60*60))/10) .. " weeks"
|
||||
elseif delta >= 2*24*60*60 then -- if more than 2 days
|
||||
delta = tostring(math.floor(delta/(24*60*60))/10) .. " days"
|
||||
elseif delta >= 2*60*60 then -- if more than 2 hours
|
||||
delta = tostring(math.floor(delta/(60*60/10))/10) .. " hours"
|
||||
elseif delta >= 2*60 then -- if more then 2 minutes
|
||||
delta = tostring(math.floor(delta/(60/10))/10) .. " minutes"
|
||||
else
|
||||
delta = tostring(delta) .. " seconds"
|
||||
end
|
||||
return delta
|
||||
end
|
||||
|
||||
timing.display = function(n)
|
||||
local function _display(n)
|
||||
local time = timing[n]
|
||||
local previous = timing[n - 1]
|
||||
|
||||
local delta = time.time - previous.time
|
||||
if delta >= 2*60*60 then -- if more than 2 hours
|
||||
delta = tostring(math.floor(delta/(60*60/10))/10) .. " hours"
|
||||
elseif delta >= 120 then -- if more then 2 minutes
|
||||
delta = tostring(math.floor(delta/(60/10))/10) .. " minutes"
|
||||
else
|
||||
delta = tostring(delta) .. " seconds"
|
||||
end
|
||||
local delta = human_readable_time(time.time - previous.time)
|
||||
|
||||
print(delta, previous.label)
|
||||
end
|
||||
@@ -34,4 +42,10 @@ timing.mark = function(label)
|
||||
end
|
||||
end
|
||||
|
||||
timing.estimate = function(current_position, total_operations)
|
||||
local delta = os.time() - timing[#timing].time
|
||||
local estimate = delta * total_operations / current_position - delta
|
||||
return human_readable_time(estimate)
|
||||
end
|
||||
|
||||
return timing
|
||||
|
||||
Reference in New Issue
Block a user