Skip to content
Browse files

optimized speed for full_process()

  • Loading branch information...
1 parent ed3d47f commit 3a8b46226dbd0f48e86acbfa02fe1fbf44a521b3 @medecau medecau committed Nov 14, 2011
Showing with 16 additions and 2 deletions.
  1. +7 −0 fuzzywuzzy/benchmarks.py
  2. +0 −1 fuzzywuzzy/tests.py
  3. +9 −1 fuzzywuzzy/utils.py
View
7 fuzzywuzzy/benchmarks.py
@@ -51,3 +51,10 @@
print 'Test for string: "%s"' % s
#print 'Old: %f' % round(timeit('utils.asciidammitold(\'%s\')' % s, "import utils",number=iterations),4)
print 'New: %f' % round(timeit('utils.asciidammit(\'%s\')' % s, "import utils",number=iterations),4)
+
+print
+
+for s in mixed_strings+cirque_strings+choices:
+ print 'Test for string: "%s"' % s
+ print 'Old: %f' % round(timeit('utils.full_processold(\'%s\')' % s, "import utils",number=iterations),4)
+ print 'New: %f' % round(timeit('utils.full_process(\'%s\')' % s, "import utils",number=iterations),4)
View
1 fuzzywuzzy/tests.py
@@ -31,7 +31,6 @@ def tearDown(self):
def test_asciidammit(self):
for s in self.mixed_strings:
- print '###'
utils.asciidammit(s)
class RatioTest(unittest.TestCase):
View
10 fuzzywuzzy/utils.py
@@ -12,6 +12,12 @@
for i in range(128,256):
bad_chars+=chr(i)
+pro_badchars=bad_chars
+pro_table_from=string.punctuation+string.ascii_uppercase
+pro_table_to=' '*len(string.punctuation)+string.ascii_lowercase
+pro_table=string.maketrans(pro_table_from, pro_table_to)
+
+
def asciionly(s):
return s.translate(None, bad_chars)
@@ -53,13 +59,15 @@ def validate_string(s):
except:
return False
-def full_process(s):
+def full_processold(s):
s = s.lower()
s = s.strip()
s = remove_punctuation(s)
x = asciidammit(s)
return x
+def full_process(s):
+ return s.translate(pro_table, bad_chars).strip()

0 comments on commit 3a8b462

Please sign in to comment.
Something went wrong with that request. Please try again.