Can anyone explain the performance difference between scan_forward()
and scan_reversed()
?
#1034
Answered
by
niklasf
jacksonthall22
asked this question in
Q&A
-
On my machine,
Looking at the implementations, it seems like they do almost exactly the same things. Can anyone explain this magic in detail?
|
Beta Was this translation helpful? Give feedback.
Answered by
niklasf
Aug 9, 2023
Replies: 1 comment
-
It's really just the extra As an optimization, the library internals already use |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jacksonthall22
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's really just the extra
&
and-
on integers. Bitwise operations aren't as fast in Python as in other languages, and-bb
is costly because it's not wrapping at 64 bits.As an optimization, the library internals already use
scan_reversed()
where the iteration order is not observable.