.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_benchmark_dot_cython.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_dot_cython.py: .. _l-example-dot-cython: Compares dot implementations (numpy, cython, c++, sse) ====================================================== :epkg:`numpy` has a very fast implementation of the dot product. It is difficult to be better and very easy to be slower. This example looks into a couple of slower implementations with cython. The tested functions are the following: * :func:`dot_product ` `code `_ * :func:`ddot_cython_array ` `code `_ * :func:`ddot_cython_array_optim ` `code `_ * :func:`ddot_array ` `code `_ * :func:`ddot_array_16 ` `code `_ * :func:`ddot_array_16_sse ` `code `_ .. contents:: :local: .. GENERATED FROM PYTHON SOURCE LINES 37-62 .. code-block:: default import numpy import matplotlib.pyplot as plt from pandas import DataFrame, concat from td3a_cpp.tutorial.dot_cython import ( dot_product, ddot_cython_array, ddot_cython_array_optim, ddot_array, ddot_array_16, ddot_array_16_sse ) from td3a_cpp.tutorial.dot_cython import ( sdot_cython_array, sdot_cython_array_optim, sdot_array, sdot_array_16, sdot_array_16_sse ) from td3a_cpp.tools import measure_time_dim def get_vectors(fct, n, h=100, dtype=numpy.float64): ctxs = [dict(va=numpy.random.randn(n).astype(dtype), vb=numpy.random.randn(n).astype(dtype), dot=fct, x_name=n) for n in range(10, n, h)] return ctxs .. GENERATED FROM PYTHON SOURCE LINES 63-66 numpy dot +++++++++ .. GENERATED FROM PYTHON SOURCE LINES 66-74 .. code-block:: default ctxs = get_vectors(numpy.dot, 10000) df = DataFrame(list(measure_time_dim('dot(va, vb)', ctxs, verbose=1))) df['fct'] = 'numpy.dot' print(df.tail(n=3)) dfs = [df] .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/100 [00:00` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_benchmark_dot_cython.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_