Skip to content

Instantly share code, notes, and snippets.

@WarrenWeckesser
Created November 11, 2022 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WarrenWeckesser/3d3369a4be933ec699e3a3390a01e55f to your computer and use it in GitHub Desktop.
Save WarrenWeckesser/3d3369a4be933ec699e3a3390a01e55f to your computer and use it in GitHub Desktop.
Script to check the effect of https://github.com/scipy/scipy/pull/17397 on performance.
import subprocess
from timeit import timeit
import numpy as np
import scipy
from scipy.signal import upfirdn, resample_poly
try:
from scipy.signal._upfirdn_apply import _output_len
except ImportError:
from scipy.signal._upfirdn import _output_len
def get_git_branch_name():
result = subprocess.check_output(['git', 'branch', '--show-current'],
cwd='/home/warren/repos/git/forks/scipy')
return result.decode('ascii').strip()
print(f'{scipy.__version__=} (branch: {get_git_branch_name()})')
len_h = 127
in_len = 10**6
up = 320
down = 441
n = 25_000_000
result = timeit('_output_len(len_h, in_len, up, down)',
number=n, globals=globals())
print(f'_output_len: {result/n*1e9:8.2f} ns')
h = np.full(len_h, fill_value=1/len_h)
x = np.sin(0.1*np.arange(in_len))
n = 2000
result = timeit('upfirdn(h, x, up, down)', number=n, globals=globals())
print(f'upfirdn: {result/n*1e3:8.2f} ms')
n = 2000
result = timeit('resample_poly(x, up, down)', number=n, globals=globals())
print(f'resample_poly: {result/n*1e3:8.2f} ms')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment