{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example 5.2: Molli XT Benchmark\n", "\n", "## Hardware Specification for Rerun\n", "\n", "Desktop workstation with 2x (AMD EPYC 7702 64-Core) with total of 128 physical and 256 logical cores, 1024 GB DDR4 with Ubuntu 22.04 LTS operating system." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import molli as ml\n", "import molli_xt\n", "from scipy.spatial.distance import cdist\n", "import numpy as np\n", "import timeit\n", "\n", "arr1 = np.random.rand(100, 30, 3).astype(\"f4\")\n", "test_arrs = {\n", " size: np.random.rand(size, 3).astype(\"f4\") for size in (10, 100, 1000, 10000, 20000)\n", "}" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Distance (Euclidean) calculation with scipy.cdist:\n", "size=10: t_sp/t_ml=9.535875 molli=0.001277 scipy=0.012177\n", "size=100: t_sp/t_ml=3.079132 molli=0.006536 scipy=0.020125\n", "size=1000: t_sp/t_ml=4.997022 molli=0.065151 scipy=0.325563\n", "size=10000: t_sp/t_ml=2.504050 molli=0.744849 scipy=1.865138\n", "size=20000: t_sp/t_ml=1.908507 molli=1.464665 scipy=2.795323\n" ] } ], "source": [ "# Comparison for euclidean distance\n", "print(\"Distance (Euclidean) calculation with scipy.cdist:\")\n", "for size, arr2 in test_arrs.items():\n", " times_scipy = timeit.Timer(\n", " \"\"\"[cdist(x, arr2, \"sqeuclidean\") for x in arr1]\"\"\",\n", " globals=globals(),\n", " ).repeat(5, 10)\n", "\n", " times_molli = timeit.Timer(\n", " \"\"\"molli_xt.cdist32f_eu2(arr1, arr2)\"\"\",\n", " globals=globals(),\n", " ).repeat(5, 10)\n", "\n", " t_sp = min(times_scipy)\n", " t_ml = min(times_molli)\n", "\n", " print(f\"{size=}: {t_sp/t_ml=:3f} molli={t_ml:4f} scipy={t_sp:4f}\")\n" ] } ], "metadata": { "kernelspec": { "display_name": "dev-blake", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.6" } }, "nbformat": 4, "nbformat_minor": 2 }