Howdy!

Get ready for a bunch of nonsense articles and complaining. Articles written in neovim, btw.

python benchmark - calculating a power of 2

Introduction What is the fastest way of calculating a power of 2 in python? Not that it really matters, but here it is. I’ve tested 4 approaches: bit shifting ‘**’ operator builtin pow() function math.pow() function Test env $ python3 --version Python 3.13.2 $ uname -rm 6.14.2-arch1-1 x86_64 Functions along their disassembled bytecode bit shift def bitshift(x: int) -> int: return 1 << x 1 RESUME 0 2 LOAD_CONST 1 (1) LOAD_FAST 0 (x) BINARY_OP 3 (<<) RETURN_VALUE ’**’ operator ...

21.04.2025 · 4 min · jkb