Skip to content

Conversation

@eendebakpt
Copy link
Contributor

The buffer initialization (which happens many times) is improved by replacing the multiplication with a sum.

@JelleZijlstra
Copy link
Member

Have you benchmarked this? MOVE_COST is 2, so the multiplication should just be a bitshift. Chances are that's faster than an additional memory read.

@eendebakpt
Copy link
Contributor Author

@JelleZijlstra Fair point. As long as MOVE_COST is a power of two the compiler can indeed optimize and there is no gain. I benchmarked on my system with MOVE_COST=2 (just the buffer filling in a large for loop):

current main: 1.48 seconds
original PR: 1.55 seconds
updated PR: 0.89 seconds

@eendebakpt eendebakpt changed the title Improve efficiency of lehvensthein_distance method Improve efficiency of lehvenshtein_distance method Apr 22, 2022
@JelleZijlstra JelleZijlstra merged commit feb45d0 into python:main May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants