inline functions

from transonic import boost

T = int


@boost(inline=True)
def add(a: T, b: T) -> T:
    return a + b


@boost
def use_add(n: int = 10000):
    tmp: T = 0
    _: T
    for _ in range(n):
        tmp = add(tmp, 1)
    return tmp


if __name__ == "__main__":

    from transonic.util import timeit

    n = 100000
    assert n == use_add(n)

    print(f"{timeit('use_add(n)', globals=locals()): .2e} s")

Compiled with:

transonic -b pythran add.py
transonic -b numba add.py
transonic -b cython add.py

Gives:

TRANSONIC_NO_REPLACE=1 python add.py
 8.43e-03 s
TRANSONIC_BACKEND="pythran" python add.py
 1.34e-07 s
TRANSONIC_BACKEND="numba" python add.py
 1.53e-07 s
TRANSONIC_BACKEND="cython" python add.py
 3.24e-07 s

The three backends (and their compiler) give very good speedup!