Reputation: 24887
Is there a way to read how many Python virtual machine instructions have been interpreted since the virtual machine started? I realise this may (if possible at all) only be applicable to CPython.
Upvotes: 9
Views: 1379
Reputation: 5602
Not easily. The canonical way to measure performance is to use one of the profiling modules available. Still...
In CPython 2, it is possible to get an approximate measurement, for the current thread, from an extension module (i.e. C code) by reading the PyThreadState
structure. There is a field called tick_counter
which, when multiplied by the check interval, it results in the number of bytecode instructions executed. Or, in other words, the number of iterations of the interpreter main loop.
But as the check interval may change during the execution, this value is not precise.
Interesting links for CPython 2.7.4:
Since CPython 3.2 the tick_counter
lost its real meaning, so you're forced to use the tracing or profiling already mentioned:
Upvotes: 2