Commit 6958e77
authored
[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 (#20852)1 parent a20e897 commit 6958e77
File tree
7 files changed
+77
-0
lines changed- mypyc
- doc
- lib-rt
- primitives
- test-data
- fixtures
7 files changed
+77
-0
lines changed| 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 | |
|---|---|---|---|
| |||
781 | 781 | | |
782 | 782 | | |
783 | 783 | | |
| 784 | + | |
784 | 785 | | |
785 | 786 | | |
786 | 787 | | |
| |||
| 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 | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
408 | 417 | | |
409 | 418 | | |
410 | 419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| 135 | + | |
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
983 | 983 | | |
984 | 984 | | |
985 | 985 | | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1269 | 1269 | | |
1270 | 1270 | | |
1271 | 1271 | | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
0 commit comments