.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_benchmark_filter.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_benchmark_filter.py: .. _l-example-filter: Compares filtering implementations (numpy, cython) ================================================== The benchmark looks into different ways to implement thresholding: every value of a vector superior to *mx* is replaced by *mx*. It compares several implementation to :epkg:`numpy`. * :func:`cfilter_dmax ` `code `_ * :func:`cfilter_dmax2 ` `code `_ * :func:`cfilter_dmax4 ` `code `_ * :func:`cfilter_dmax16 ` `code `_ * :func:`cyfilter_dmax ` `code `_ * :func:`filter_dmax_cython ` `code `_ * :func:`filter_dmax_cython_optim ` `code `_ * :func:`pyfilter_dmax ` `code `_ .. GENERATED FROM PYTHON SOURCE LINES 41-86 .. code-block:: default import pprint import numpy import matplotlib.pyplot as plt from pandas import DataFrame from td3a_cpp.tutorial.experiment_cython import ( pyfilter_dmax, filter_dmax_cython, filter_dmax_cython_optim, cyfilter_dmax, cfilter_dmax, cfilter_dmax2, cfilter_dmax16, cfilter_dmax4 ) from td3a_cpp.tools import measure_time_dim def get_vectors(fct, n, h=200, dtype=numpy.float64): ctxs = [dict(va=numpy.random.randn(n).astype(dtype), fil=fct, mx=numpy.float64(0), x_name=n) for n in range(10, n, h)] return ctxs def numpy_filter(va, mx): va[va > mx] = mx all_res = [] for fct in [numpy_filter, pyfilter_dmax, filter_dmax_cython, filter_dmax_cython_optim, cyfilter_dmax, cfilter_dmax, cfilter_dmax2, cfilter_dmax16, cfilter_dmax4]: print(fct) ctxs = get_vectors(fct, 1000 if fct == pyfilter_dmax else 40000) res = list(measure_time_dim('fil(va, mx)', ctxs, verbose=1)) for r in res: r['fct'] = fct.__name__ all_res.extend(res) pprint.pprint(all_res[:2]) .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/200 [00:00 0%| | 0/5 [00:00 0%| | 0/200 [00:00 0%| | 0/200 [00:00 0%| | 0/200 [00:00 0%| | 0/200 [00:00 0%| | 0/200 [00:00 0%| | 0/200 [00:00 0%| | 0/200 [00:00` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_benchmark_filter.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_