Python performance: Hello numba.

This commit is contained in:
Julien Palard 2023-06-22 11:57:41 +02:00
parent 1a2c0816c3
commit a95bc5fe97
Signed by: mdk
GPG Key ID: 0EFC1AC1006886F8
3 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,11 @@
from numba import njit
@njit
def collatz_length(n):
if n == 1:
return 0
if n % 2 == 0:
return 1 + collatz_length(n // 2)
elif n % 2 == 1:
return 1 + collatz_length(n * 3 + 1)

View File

@ -501,6 +501,21 @@ $ cython -a include/collatz_length_annotated.py
# Numba
Numba est un `JIT` : « Just In Time compiler ».
```python
#!cat include/collatz_length_numba.py
```
## Numba démo
```shell
$ python -m pyperf timeit \
> -s 'from include.collatz_length_numba import collatz_length' \
> 'collatz_length(837799)'
#!cache -- python -m pyperf timeit --fast -s 'from include.collatz_length_numba import collatz_length' 'collatz_length(837799)'
```
# mypyc
# Pythran

View File

@ -2,3 +2,4 @@ pyperf
cython
snakeviz
scalene
numba