Skip to content

[fork-ffi] purescript-lua-console: implement console timers (time/timeLog/timeEnd) #2

@Unisay

Description

@Unisay

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions