2 ms·
The evaluations don't magically/implicitly happen on many cores. I guess the first thing worth doing when analyzing this would be looking at the differences in
by kunley 3y ago
The evaluations don't magically/implicitly happen on many cores.
I guess the first thing worth doing when analyzing this would be looking at the differences in the bytecode, then looking at the C code implementing the differing bytecode ops. But there also other factors, like the new adaptive interpreter trying to JIT the code.
- zimpenfish 3y agoFor Python 3.12, Godbolt gave almost identical bytecode for both (albeit in different order.) I'm guessing wildly but might this be because `BINARY_OP(+=)` stores the result (because it's `INPLACE`) and then you also do `STORE_FAST(x)` which gives you two stores for the same value compared with one store in the single-line version? Single-line dual assignment: 2 2 LOAD_FAST 0 (a2) 4 LOAD_FAST 1 (c) 6 BINARY_OP 0 (+) 10 LOAD_FAST 1 (c) 12 LOAD_CONST 1 (2) 14 BINARY_OP 0 (+) 18 STORE_FAST 1 (c) 20 STORE_FAST 0 (a2) vs the two-line version: 2 2 LOAD_FAST 0 (a2) 4 LOAD_FAST 1 (c) 6 BINARY_OP 13 (+=) 10 STORE_FAST 0 (a2) 7 12 LOAD_FAST 1 (c) 14 LOAD_CONST 1 (2) 16 BINARY_OP 13 (+=) 20 STORE_FAST 1 (c)