info cmdcount

info cmdcount

Returns a count of the total number of commands that have been invoked in this interpreter.


Note that since the bytecode compiler arrived in Tcl 8.0, the machinery that counts command invocations has been effectively disconnected from the operation of many Tcl commands. As development continues, more and more command evaluation doesn't count in the eyes of info cmdcount.

This command is best treated in modern Tcl programs as a curious historical relic. Not to be relied on for correct operation of scripts.

Lars H 2008-05-24: The above was written in 2003. Is it still true? I recall discussions about bytecode generation and cmdcount to have surfaced several times in the meantime, in a way that suggests core maintainers still care about upholding the cmdcount. It is used by interp limit, is it not?

PYK 2014-06-20: info cmdcount has always been reliable for the uses I've put it to. I haven't yet come across a situation where info cmdcount isn't incremented after a command has been executed.

APN 2017-01-13: Not so. As of 8.6.6, info cmdcount is still unreliable. See http://core.tcl.tk/tcl/tktview?name=931e4956b9 .

JMN 2023-06: I've seen it used as a way to get a quick and dirty 'unique' id for command names etc. Note though that in Tcl 8.6.13 (at least) it goes negative around 2.1Billion and then increments towards zero. The wraparound is something to be aware of - especially if the script isn't expecting the negative sign or is comparing values to determine something like relative command creation order.

See Also

info