how long do the different python-vm bytecodes take?

G

GHUM

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?
 
T

Terry Reedy

|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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top