Message215594
fast_translate.patch works only with ASCII input string and ASCII 1:1 mapping. Is this actually typical case?
Here is a patch which uses different approach. It caches values for ASCII keys. It works with all types of input strings and mappings and can speed up more use cases, including non-ASCII data, deletion and enlarging.
translate_timing.py results:
unpatched patched
Testing 1-1 translation
str.translate 4.55125927699919 0.7898181750006188
str.translate from bytes trans 1.8910855210015143 0.779950579000797
Testing deletion
str.translate 4.481863372000589 0.7718261509999138
Testing enlarging translations
str.translate 4.421521270000085 0.9290620680003485
translate_script_ascii.py results:
---------------------------+---------------------------+-------------------------------
Tests                     | translate_script_ascii.34 | translate_script_ascii.cached3
---------------------------+---------------------------+-------------------------------
replace none, length=10Â Â Â | Â Â Â Â Â Â Â Â Â Â 6.12 us (+176%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 2.22 us (*)
replace none, length=10**3 | Â Â Â Â Â Â Â Â Â Â 448 us (+1293%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 32.2 us (*)
replace none, length=10**6 | Â Â Â Â Â Â Â Â Â Â 474 ms (+1435%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 30.9 ms (*)
replace 10%, length=10Â Â Â Â | Â Â Â Â Â Â Â Â Â Â 5.73 us (+133%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 2.46 us (*)
replace 10%, length=10**3Â | Â Â Â Â Â Â Â Â Â Â 412 us (+1060%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 35.5 us (*)
replace 10%, length=10**6Â | Â Â Â Â Â Â Â Â Â Â 442 ms (+1204%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 33.9 ms (*)
replace 50%, length=10Â Â Â Â | Â Â Â Â Â Â Â Â Â Â Â 4.75 us (+85%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 2.57 us (*)
replace 50%, length=10**3Â | Â Â Â Â Â Â Â Â Â Â Â 311 us (+552%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 47.7 us (*)
replace 50%, length=10**6Â | Â Â Â Â Â Â Â Â Â Â Â 331 ms (+617%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 46.2 ms (*)
replace 90%, length=10Â Â Â Â | Â Â Â Â Â Â Â Â Â Â Â 3.36 us (+29%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 2.59 us (*)
replace 90%, length=10**3Â | Â Â Â Â Â Â Â Â Â Â Â 178 us (+250%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 50.8 us (*)
replace 90%, length=10**6Â | Â Â Â Â Â Â Â Â Â Â Â 192 ms (+291%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 49.2 ms (*)
replace all, length=10Â Â Â Â | Â Â Â Â Â Â Â Â Â Â Â 2.64 us (+28%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 2.06 us (*)
replace all, length=10**3Â | Â Â Â Â Â Â Â Â Â Â Â 146 us (+189%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 50.3 us (*)
replace all, length=10**6Â | Â Â Â Â Â Â Â Â Â Â Â 152 ms (+194%) | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 51.7 ms (*)
---------------------------+---------------------------+-------------------------------
Total                     |          1.59 sec (+651%) |                     212 ms (*)
---------------------------+---------------------------+------------------------------- |
|
| Date |
User |
Action |
Args |
| 2014-04-05 11:47:44 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, pitrou, vstinner, ezio.melotti, python-dev, josh.r |
| 2014-04-05 11:47:43 | serhiy.storchaka | set | messageid: <1396698463.65.0.734385875942.issue21118@psf.upfronthosting.co.za> |
| 2014-04-05 11:47:43 | serhiy.storchaka | link | issue21118 messages |
| 2014-04-05 11:47:41 | serhiy.storchaka | create | |
|