STINNER Victor added the comment: fast_translate.patch: here is the real patch which optimize translating ASCII to ASCII. It's *much* faster:
---------------------------+-------------+--------------- Tests | writerA | fastA ---------------------------+-------------+--------------- replace none, length=10 | 710 ns (*) | 169 ns (-76%) replace none, length=10**3 | 59.1 us (*) | 997 ns (-98%) replace none, length=10**6 | 59.2 ms (*) | 805 us (-99%) replace 10%, length=10 | 678 ns (*) | 187 ns (-72%) replace 10%, length=10**3 | 58.7 us (*) | 1.02 us (-98%) replace 10%, length=10**6 | 57.5 ms (*) | 817 us (-99%) replace 50%, length=10 | 559 ns (*) | 188 ns (-66%) replace 50%, length=10**3 | 43.6 us (*) | 1.02 us (-98%) replace 50%, length=10**6 | 43.4 ms (*) | 811 us (-98%) replace 90%, length=10 | 437 ns (*) | 187 ns (-57%) replace 90%, length=10**3 | 32.4 us (*) | 1.02 us (-97%) replace 90%, length=10**6 | 31.8 ms (*) | 805 us (-97%) replace all, length=10 | 386 ns (*) | 121 ns (-69%) replace all, length=10**3 | 27.3 us (*) | 955 ns (-96%) replace all, length=10**6 | 27.2 ms (*) | 807 us (-97%) ---------------------------+-------------+--------------- Total | 219 ms (*) | 4.05 ms (-98%) ---------------------------+-------------+--------------- I'm not sure yet that the patch doesn't make non-ASCII cases slower. ---------- Added file: http://bugs.python.org/file34731/fast_translate.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue21118> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com