February 2019
Intermediate to advanced
672 pages
16h 50m
English
Sometimes it's not easy to estimate how many operations a Python statement will take. In this section, we will dig into the Python internals to estimate the performance of individual statements. In the CPython interpreter, Python code is first converted to an intermediate representation, the bytecode, and then executed by the Python interpreter.
To inspect how the code is converted to bytecode, we can use the dis Python module (dis stands for disassemble). Its usage is really simple; all that is needed is to call the dis.dis function on the ParticleSimulator.evolve method:
import dis from simul import ParticleSimulator dis.dis(ParticleSimulator.evolve)
This will print, for each line in the function, a list of bytecode instructions. ...