-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbenchmark.py
45 lines (32 loc) · 1.29 KB
/
benchmark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from timeit import timeit
n_attempts = 1000
n_coordinates = 10000
setup = """
import numpy as np
from skimage.data import coins
from interpolation_numba import interpolation_numba
from interpolation import (interpolation_cython,
interpolation_simd, interpolation_normal)
image = coins().astype(np.float32)
height, width = image.shape
n_coordinates = {}
xs = np.random.uniform(0, width-1, n_coordinates)
ys = np.random.uniform(0, height-1, n_coordinates)
coordinates = np.column_stack((xs, ys)).astype(np.float32)
# precompile jit
interpolation_numba(image, coordinates)
""".format(n_coordinates)
print("number of attempts :", n_attempts)
print("number of coordinates :", n_coordinates)
time = timeit("interpolation_normal(image, coordinates)",
setup=setup, number=n_attempts)
print("C for loop : {:8f} [s]".format(time))
time = timeit("interpolation_simd(image, coordinates)",
setup=setup, number=n_attempts)
print("C SIMD : {:8f} [s]".format(time))
time = timeit("interpolation_cython(image, coordinates)",
setup=setup, number=n_attempts)
print("Cython : {:8f} [s]".format(time))
time = timeit("interpolation_numba(image, coordinates)",
setup=setup, number=n_attempts)
print("Numba : {:8f} [s]".format(time))