Sometimes, it's not easy to evaluate how many operations a Python statement will take. In this section, we will explore Python internals to estimate the performance of Python statements. Python code gets converted to an intermediate representation—called bytecode—that gets executed by the Python virtual machine.
To help inspect how the code gets converted into bytecode we can use the Python module
dis (disassemble). Its usage is really simple, it is sufficient to call the function
dis.dis on the
import dis from simul import ParticleSimulator dis.dis(ParticleSimulator.evolve)
This will generate, for each line, a list of bytecode instructions. For example, the statement
v_x = (-p.y)/norm is expanded ...