Needless to say that Python is quite slow for mathematical and scientific calculations as compare to other programming languages such as C and C++. However, to speed up the Python calculations, Intel software team has been developing the Python distribution for making Python faster.
This Intel software suite is actually built on top of Anaconda's Python distribution, and both distributions already come with the Intel MKL library. Moreover, Intel also provides other libraries, such as Data Analytics Acceleration Library (DAAL) and Threading Building Blocks (TBB) among others. In this post, I would like to show how to step-by-step benchmark the performance of Python between Anaconda and Intel.
I suggest you create new environment for this project. For example:
conda create -n intel python=3activate intelpip install daskpip install dask[array]or
conda install tbbpip install tbb4pyor
conda install tbbTip: Full installation of Intel Distribution for Python can be found here.
QR decomposition in Python will be used here as a tester for benchmarking the performance of Anaconda's Python distribution and Intel's Python distribution.
For a square matrix A the QR Decomposition converts A into the product of an orthogonal matrix Q (i.e. (Q^T)(Q) = I) and an upper triangular matrix R. Hence: A=QR.
Create a Python script and append the following source code into it, for example: bench.py
import dask, timeimport dask.array as dax = da.random.random((100000, 2000), chunks=(10000, 2000))t0 = time.time()q, r = da.linalg.qr(x)test = da.all(da.isclose(x, q.dot(r)))assert(test.compute()) # compute(scheduler="threads") by defaultprint(time.time() - t0)This script will generate random set of numbers and then compute the QR factorization of a matrix (source code of Dask's QR function is here), which is equivalent to Numpy's QR calculation function.
1. Restart your machine and close all other applications before running the tests.
2. Open cmd (or terminal for Linux and macOS users).
3. Suppose that you already stay in a new environment. Now you are ready to execute the script.
Anaconda distrubiton for Python
python bench.pyIntel distribution for Python
python -m tbb bench.pyNote that the test can take 1-2 minutes depending on the system.
116.941629886627291.34923768043518You can see that Intel Python distribution is at least 15-20% faster than that of Anaconda.
Rangsiman Ketkaew