Browse files

Changes to utils.validate_string() and benchmarks

  • Loading branch information...
1 parent 5a45712 commit 93e45a7e1e03db0792d33ae8f7eb7955b990f4cf @medecau medecau committed Nov 3, 2011
Showing with 27 additions and 1 deletion.
  1. +17 −0 fuzzywuzzy/benchmarks.py
  2. +10 −1 fuzzywuzzy/utils.py
View
17 fuzzywuzzy/benchmarks.py
@@ -12,8 +12,25 @@
"zarakana - cirque du soleil - bellagio"
]
+choices = [
+ "",
+ "new york yankees vs boston red sox",
+ "",
+ "zarakana - cirque du soleil - bellagio",
+ None,
+ "cirque du soleil las vegas",
+ None
+]
+
for s in cirque_strings:
print 'Test for string: "%s"' % s
print 'Old: %f' % round(timeit('utils.remove_punctuationold(\'%s\')' % s, "import utils",number=iterations),4)
print 'New: %f' % round(timeit('utils.remove_punctuation(\'%s\')' % s, "import utils",number=iterations),4)
+
+print
+
+for s in choices:
+ print 'Test for string: "%s"' % s
+ print 'Old: %f' % round(timeit('utils.validate_stringold(\'%s\')' % s, "import utils",number=iterations*10),4)
+ print 'New: %f' % round(timeit('utils.validate_string(\'%s\')' % s, "import utils",number=iterations*10),4)
View
11 fuzzywuzzy/utils.py
@@ -34,14 +34,23 @@ def remove_punctuationold(s):
def remove_punctuation(s):
return string.translate(s, punctuation_table)
-def validate_string(s):
+def validate_stringold(s):
if s is None: return False
try:
if len(s) == 0: return False
except:
return False
return True
+def validate_string(s):
+ try:
+ if len(s)>0:
+ return True
+ else:
+ return False
+ except:
+ return False
+
def full_process(s):
s = s.lower()
s = s.strip()

0 comments on commit 93e45a7

Please sign in to comment.