Created
February 25, 2015 14:02
-
-
Save ewmoore/5f34c148b00ed461057d to your computer and use it in GitHub Desktop.
Benchmark script for numpy#5509
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import numpy as np | |
from numpy.testing import measure | |
def bench_inf_norm_1d(dtype='d', strided=False, with_nan=False): | |
vec_size = [10, 100, 1000, 10000, 100000, 1000000 ] | |
repeat = [100000, 100000, 100000, 40000, 7500, 1000] | |
call_both = lambda x: abs(x).max() | |
call_norm = lambda x: np.linalg.norm(x, np.inf) | |
call_max = np.maximum.reduce | |
max_abs = np.max_abs.reduce | |
print(np.dtype(dtype)) | |
for size, rep in zip(vec_size, repeat): | |
if strided: | |
v = np.random.randn(3*size).astype(dtype)[::3] | |
else: | |
v = np.random.randn(size).astype(dtype) | |
if with_nan: | |
v[2] = np.nan | |
t_both = measure('call_both(v)', rep) | |
t_norm = measure('call_norm(v)', rep) | |
t_max = measure('call_max(v)', rep) | |
t_ma = measure('max_abs(v)', rep) | |
print('{0:7} {1:6.2f} {2:6.2f} {3:6.2f} {4:6.2f} {5:6} {6:6.2f}'.format(size, t_norm, t_both, t_ma, t_max, rep, t_both/t_ma)) | |
def bench_inf_norm_2d(dtype): | |
size_rep = np.array([[3, 10, 50000], | |
[3, 100, 50000], | |
[3, 1000, 25000], | |
[3, 10000, 5000], | |
[100, 10, 10000], | |
[100, 100, 20000], | |
[100, 1000, 2500], | |
[100, 10000, 250], | |
[1000, 10, 10000], | |
[1000, 100, 2500], | |
[1000, 1000, 250], | |
[1000, 10000, 30], | |
[10000, 10, 1000], | |
[10000, 100, 250], | |
[10000, 1000, 25], | |
[10000, 10000, 3]]) | |
vec_size = [3, 16, 100, 500, 1000, 10000] | |
n_vec = [1, 5, 10, 100, 1000, 10000] | |
call_both = lambda x, a: np.absolute(x).max(axis=a) | |
call_norm = lambda x, a: np.linalg.norm(x, np.inf, axis=a) | |
call_max = lambda x, a: np.maximum.reduce(x, axis=a) | |
max_abs = lambda x, a: np.max_abs.reduce(x, axis=a) | |
print(np.dtype(dtype)) | |
for size0, size1, rep in size_rep: | |
v = np.random.randn(size0, size1).astype(dtype) | |
t_both0 = measure('call_both(v, 0)', rep) | |
t_norm0 = measure('call_norm(v, 0)', rep) | |
t_max0 = measure('call_max(v, 0)', rep) | |
t_ma0 = measure('max_abs(v, 0)', rep) | |
print('{0:6} ({1:6}, {2:6}) {3:6.2f} {4:6.2f} {5:6.2f} {6:6.2f} {7:6} {8:6.2f}'.format(0, size0, size1, t_norm0, t_both0, t_ma0, t_max0, rep, t_both0/t_ma0)) | |
t_both1 = measure('call_both(v, 1)', rep) | |
t_norm1 = measure('call_norm(v, 1)', rep) | |
t_max1 = measure('call_max(v, 1)', rep) | |
t_ma1 = measure('max_abs(v, 1)', rep) | |
print('{0:6} ({1:6}, {2:6}) {3:6.2f} {4:6.2f} {5:6.2f} {6:6.2f} {7:6} {8:6.2f}'.format(1, size0, size1, t_norm1, t_both1, t_ma1, t_max1, rep, t_both1/t_ma1)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment