From 43163053a58193b81d37c52f369f849d6a3125c3 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Sun, 12 May 2019 10:02:46 -0400 Subject: [PATCH] Lua: timing --- sys/apis/map.lua | 2 ++ sys/apis/util.lua | 3 +++ sys/apps/Lua.lua | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/apis/map.lua b/sys/apis/map.lua index 9e4ab93..a6b033c 100644 --- a/sys/apis/map.lua +++ b/sys/apis/map.lua @@ -6,6 +6,8 @@ local Map = { } -- TODO: refactor Map.merge = Util.merge Map.shallowCopy = Util.shallowCopy +Map.find = Util.find +Map.filter = Util.filter function Map.removeMatches(t, values) local function matchAll(entry) diff --git a/sys/apis/util.lua b/sys/apis/util.lua index f1f5a8d..e774ed9 100644 --- a/sys/apis/util.lua +++ b/sys/apis/util.lua @@ -77,6 +77,9 @@ function Util.tostring(pattern, ...) end if type(pattern) == 'string' then + if select('#', ...) == 0 then + return pattern + end return _sformat(pattern, ...) elseif type(pattern) == 'table' then return serialize(pattern, term.current().getSize()) diff --git a/sys/apps/Lua.lua b/sys/apps/Lua.lua index 5627d6c..4eba8ab 100644 --- a/sys/apps/Lua.lua +++ b/sys/apps/Lua.lua @@ -294,6 +294,7 @@ end function page:rawExecute(s) local fn, m local wrapped + local t = os.clock() fn = load('return (' ..s.. ')', 'lua', nil, sandboxEnv) @@ -319,7 +320,7 @@ function page:rawExecute(s) local bg, fg = term.getBackgroundColor(), term.getTextColor() term.setTextColor(colors.cyan) term.setBackgroundColor(colors.black) - term.write(string.format('out [%d]: ', counter)) + term.write(string.format('out [%.2f]: ', os.clock() - t)) term.setBackgroundColor(bg) term.setTextColor(fg) Util.print(m or 'nil')