Many thanks for this optimised version.

I don't find the $ctimems bug you report.

But I found this morning that there was considerable drift between $ctime and the integer part of $ctimems. But no idea why.

If the ticks-based calculation can drift, then you cannot append the ms calc to the end of $ctime either.

That said, I really appreciate the ideas about speed. Of course the big delay is the loop waiting for $ctime to click over which can be up to a second. But the speed optimisations might be useful for the whole of the rest of my script which processes practically every message as an event - and if it takes too long it can be overwhelmed by the quantity of messages in one or several busy channels.

How much benefit is there from !command and $~identifier and use of a hash table rather than variable lookup and using several inline calculations rather than one $calc? Is this something I should be doing throughout my script?