Skip to content

Instantly share code, notes, and snippets.

@mikejs
Created July 12, 2010 21:12
Show Gist options
  • Save mikejs/473066 to your computer and use it in GitHub Desktop.
Save mikejs/473066 to your computer and use it in GitHub Desktop.
# Levenshtein Distance:
# NLTK: 446.74 usec/call
# strfry: 1.86 usec/call
import timeit
nltk_lev = timeit.Timer(stmt="nltk.metrics.edit_distance('this is a string', 'this is another string')",
setup="import nltk.metrics")
str_lev = timeit.Timer(stmt="strfry.levenshtein_distance('this is a string', 'this is another string')",
setup="import strfry")
print "Levenshtein Distance:"
print "NLTK: %.2f usec/call" % nltk_lev.timeit()
print "strfry: %.2f %f usec/call" % str_lev.timeit()
@liushuaikobe
Copy link

I try to run the code, only to find that the strfry is a C lib.

I try to install it via pip, but failed.

Could you please tell me why? And how could I get the strfry installed to calculate the levenshtein_distance between two strings efficiently?

Thanks very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment