Why is the simpler loop slower?
I checked the source code of the bytecode (python 3.11.6) and found that in the decompiled bytecode, it seems that only JUMP_BACKWARD will execute a warmup function, which will trigger specialization in python 3.11 when executed enough times: PyObject* _Py_HOT_FUNCTION _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag) { /* … */ TARGET(JUMP_BACKWARD) { _PyCode_Warmup(frame->f_code); JUMP_TO_INSTRUCTION(JUMP_BACKWARD_QUICK); } … Read more