how long do the different python-vm bytecodes take?

Terry Reedy tjreedy at udel.edu
Mon Mar 17 15:20:25 EDT 2008


"GHUM" <haraldarminmassa at gmail.com> wrote in message 
news:0555ed9f-c5f1-4d0b-afbd-439c863e9439 at s13g2000prd.googlegroups.com...
|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?

There is no such table that I know of and there hardly could be, as the 
relative times will depend on hardware, OS, C compiler (including 
optimization settings), as well as the objects on the stack to be operated 
on.  Consider BINARY_ADD.  Pretty fast for 2 ints, arbitrarily slow for 
arbitrary user-class objects.  There are a few things knowns, such as _FAST 
versions being faster that other versions, and that eliminating unneeded 
codes is faster than not.  Developers usually test proposed 'speedup' 
changes on several platforms.

tjr






More information about the Python-list mailing list