-
Notifications
You must be signed in to change notification settings - Fork 571
Closed
Description
I installed Codon 0.15.5 and codon-jit 0.1.3 on Ubuntu 22.04.2 with Python 3.10.6. Comparing this script with Numba variant (commented line):
import codon
import numba as nb
import numpy as np
import timeit as ti
from math import atan2, sqrt
@codon.jit(pyvars=['atan2', 'sqrt'])
# @nb.njit(fastmath=True, locals=dict(w=nb.uint32))
def getGradAngle(im, grad, angle, w):
for i in range(im.size-w-1):
dx = im[i+w+1]-im[i]
dy = im[i+w]-im[i+1]
grad[i] = sqrt(dx**2+dy**2)
angle[i] = atan2(dy, dx)
w, h = 640, 480
im = np.random.rand(w*h).astype('f4')
grad = np.zeros_like(im)
angle = np.zeros_like(im)
fun = f'getGradAngle(im, grad, angle, w)'
t = 1000 * np.array(ti.repeat(stmt=fun, setup=fun, globals=globals(), number=1, repeat=10))
print(f'{fun}: {np.amin(t):6.3f}ms {np.median(t):6.3f}ms {np.sum(grad)}')
I'm getting Codon variant output:
getGradAngle(im, grad, angle, w): 1139.133ms 1145.087ms 159771.875
and Numba variant output:
getGradAngle(im, grad, angle, w): 8.377ms 8.389ms 159693.890625
Plain Python variant output:
getGradAngle(im, grad, angle, w): 1129.810ms 1135.429ms 159641.578125
Why is the Codon variant slower than even the plain Python?
Metadata
Metadata
Assignees
Labels
No labels