Times-two faster than bit-shift, for Python 3.x integers?
问题 I was looking at the source of sorted_containers and was surprised to see this line: self._load, self._twice, self._half = load, load * 2, load >> 1 Here load is an integer. Why use bit shift in one place, and multiplication in another? It seems reasonable that bit shifting may be faster than integral division by 2, but why not replace the multiplication by a shift as well? I benchmarked the the following cases: (times, divide) (shift, shift) (times, shift) (shift, divide) and found that #3