Anish Shah added the comment:

I ran regex and issuperset version on a random string. The regex one gives 
better performance. So, I have included the re.escape in the patch. 

>>> random_str = ''.join(random.choice(_LegalChars) for _ in range(10 ** 8))
>>> is_legal_key = re.compile('[%s]+' % re.escape(_LegalChars)).fullmatch
>>> Timer("is_legal_key(random_str)", setup="from __main__ import random_str, 
>>> is_legal_key").timeit(1)
0.3168252399998437
>>> def is_legal_key(key):
...     return key and set(_LegalChars).issuperset(key)
... 
>>> Timer("is_legal_key(random_str)", setup="from __main__ import random_str, 
>>> is_legal_key").timeit(1)
4.3335622880001665


Also, I have updated the patch. Can you please review it? :)

----------
Added file: http://bugs.python.org/file41841/issue26302_20160207.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to