mypy
0183a217 - [mypyc] Add primitive for int to ascii conversion (#21036)

Commit
102 days ago
[mypyc] Add primitive for int to ascii conversion (#21036) Added a primitive to convert `int`s into `bytes` objects suitable for bytes format strings, eg. `b'%d' % my_int`. Works the same as the existing `CPyTagged_Str` primitive used for formatting `str` objects, except it returns a `bytes` object instead of `str`. Currently only the bare `%d` specifier is supported, other integer specifiers and `%d` with options go through the regular CPython handling of format strings. Results in around 23% reduced runtime in this microbenchmark: ```python import time t0 = time.time() for i in range(10_000_000): val = b'%d' % i print(time.time() - t0) ``` Results: | setup | runtime (s) | | - | - | | interpreted | 0.90 | | mypyc master | 0.92 | | mypyc PR | 0.69 |
Author
Parents
Loading