Commit 93ee965
committed
[mypyc] Add
Added `str.isalnum()` similar to `str.isspace()`.
One interesting thing to point out here is that the benchmarks decline
in speed relative to the string's length:
| All-alphanumeric | mypyc (s) | Python (s) | Speedup |
|--------|----------:|------------:|--------:|
| length 1 (`'a'`) | 0.645 | 2.036 | 3.16x |
| length 10 (`'abcde12345'`) | 1.026 | 2.607 | 2.54x |
| length 100 (`'a' * 100`) | 3.599 | 7.848 | 2.18x |
| length 1 (UCS-2: U+00E9 `é`) | 0.816 | 1.976 | 2.42x |
| length 10 (UCS-2: U+00E9 * 10) | 2.091 | 2.587 | 1.24x |
| length 100 (UCS-2: U+00E9 * 100) | 14.298 | 7.814 | 0.55x |
<br />
| Non-alphanumeric (early exit) | mypyc (s) | Python (s) | Speedup |
|--------|----------:|------------:|--------:|
| length 1 (`' '`) | 0.622 | 2.006 | 3.22x |
| length 100 (`'!' * 100`) | 0.617 | 2.024 | 3.28x |
| length 100 (`'a' * 99 + '!'`) | 3.453 | 10.246 | 2.97x |
<br />
Not entirely sure how to interpret this but could it be because the
[Py_UNICODE_ISALNUM](https://github.com/python/cpython/blob/175ab31377d9e616efb95168099d8c2c9036504a/Include/cpython/unicodeobject.h#L769)
calls 4 functions internally which is more optimized in CPython due to
PGO & LTO (?)str.isalnum() primitive (python#20852)1 parent 10beda8 commit 93ee965
7 files changed
Lines changed: 77 additions & 0 deletions
File tree
- mypyc
- doc
- lib-rt
- primitives
- test-data
- fixtures
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
772 | 772 | | |
773 | 773 | | |
774 | 774 | | |
| 775 | + | |
775 | 776 | | |
776 | 777 | | |
777 | 778 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
654 | 654 | | |
655 | 655 | | |
656 | 656 | | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
383 | 383 | | |
384 | 384 | | |
385 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
386 | 395 | | |
387 | 396 | | |
388 | 397 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
803 | 803 | | |
804 | 804 | | |
805 | 805 | | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1123 | 1123 | | |
1124 | 1124 | | |
1125 | 1125 | | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
0 commit comments