Python performance: Hello numba.
This commit is contained in:
parent
1a2c0816c3
commit
a95bc5fe97
|
@ -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)
|
|
@ -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
|
||||
|
|
|
@ -2,3 +2,4 @@ pyperf
|
|||
cython
|
||||
snakeviz
|
||||
scalene
|
||||
numba
|
||||
|
|
Loading…
Reference in New Issue