The Effect.Console timer functions are stubbed out. time, timeLog and timeEnd all raise "Sorry, console timers aren't implemented yet" and ignore their label argument (src/Effect/Console.lua). On the JS backend these map to console.time(label) / console.timeLog(label) / console.timeEnd(label): a named timer keyed by the label string, used to measure elapsed time.
This issue tracks giving them a real implementation. The lint noise from the unused label was already handled in #64 by renaming the parameter to _s; this is the follow-up feature work.
Sketch
Keep a module-level table of start times keyed by label and read the clock on each call:
local timers = {}
-- time(label): timers[label] = os.clock()
-- timeLog(label): print(label .. ": " .. (os.clock() - timers[label]) * 1000 .. "ms")
-- timeEnd(label): same as timeLog, then timers[label] = nil
Caveat to decide
Stock Lua 5.1 has no millisecond wall-clock. os.clock returns CPU seconds, not wall time, and os.time is whole seconds. So the output cannot match the JS console.time semantics exactly. Options: accept os.clock (CPU time) and document the divergence, depend on a wall-clock source like socket.gettime where available, or keep the stubs and close this as won't-fix. The right call depends on whether downstream code relies on these for real timing or just for parity with the JS API surface.
The
Effect.Consoletimer functions are stubbed out.time,timeLogandtimeEndall raise"Sorry, console timers aren't implemented yet"and ignore their label argument (src/Effect/Console.lua). On the JS backend these map toconsole.time(label)/console.timeLog(label)/console.timeEnd(label): a named timer keyed by the label string, used to measure elapsed time.This issue tracks giving them a real implementation. The lint noise from the unused label was already handled in #64 by renaming the parameter to
_s; this is the follow-up feature work.Sketch
Keep a module-level table of start times keyed by label and read the clock on each call:
Caveat to decide
Stock Lua 5.1 has no millisecond wall-clock.
os.clockreturns CPU seconds, not wall time, andos.timeis whole seconds. So the output cannot match the JSconsole.timesemantics exactly. Options: acceptos.clock(CPU time) and document the divergence, depend on a wall-clock source likesocket.gettimewhere available, or keep the stubs and close this as won't-fix. The right call depends on whether downstream code relies on these for real timing or just for parity with the JS API surface.