how long do the different python-vm bytecodes take?

GHUM haraldarminmassa at gmail.com
Mon Mar 17 14:28:34 EDT 2008


I looked at the virtual machine bytecode of python programs:

def f(whatever):
    text="Hallo"+whatever
    return text

import dis
dis.dis(f)
  2           0 LOAD_CONST               1 ('Hallo')
              3 LOAD_FAST                0 (whatever)
              6 BINARY_ADD
              7 STORE_FAST               1 (text)

  3          10 LOAD_FAST                1 (text)
             13 RETURN_VALUE


and now I am curious: how long does one LOAD_FAST take? I am thinking
of something like back in the assembler-world, where there existed
tables like:

LDA  -> 2 cycles
BNE  -> 2 cycles, 3 on branch

of course, the "real time" is dependand on many factors, esp. the
speed of the processor.
But ... is there a relative scale somewhere?

Somehting like

LOAD_CONST      1 arbitraryUnit
LOAD_FAST         1.9 arbitraryUnits
RETURN_VALUE   8.0 arbitraryUnits

???

my Google queries did not reveal anything usefull so far. Any hints?






More information about the Python-list mailing list