{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b0afa3c8",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt \n",
    "import pandas as pd\n",
    "from matplotlib.pyplot import figure\n",
    "plt.rcParams.update({\n",
    "    \"text.usetex\": True,\n",
    "    \"font.family\": \"monospace\"\n",
    "})\n",
    "df = pd.read_csv('bench-simdobjsort.txt')\n",
    "\n",
    "def sizeinbytes(row):\n",
    "    if 'float' in row['name']:\n",
    "        return row['arraysize']*12# + row['arraysize']*4*2\n",
    "    else:\n",
    "        return row['arraysize']*24# + row['arraysize']*8*2\n",
    "    \n",
    "df[\"sizeinbytes\"] = df.apply(sizeinbytes, axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "7e1a5793",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 150100 characters]\n",
      "text/plain": [
       "<Figure size 1300x1300 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def getperf(df, metric):\n",
    "    simdm = \"simdobjsort<Point3D<\" + metric + \">>\"\n",
    "    scalarm = \"scalarobjsort<Point3D<\" + metric + \">>\"\n",
    "    t1 = df[df['name'].str.contains(simdm)][\"real_time\"]\n",
    "    t2 = df[df['name'].str.contains(scalarm)][\"real_time\"]\n",
    "    return np.array(t2)/np.array(t1)\n",
    "\n",
    "xf = df[df['name'].str.contains(\"scalarobjsort<Point3D<float-x>>\")][\"arraysize\"]\n",
    "xd = df[df['name'].str.contains(\"scalarobjsort<Point3D<double-x>>\")][\"arraysize\"]\n",
    "\n",
    "fig = plt.figure()\n",
    "plt.rcParams['figure.figsize'] = [13,13]\n",
    "plt.subplot(2, 2, 1)\n",
    "plt.plot(xd, getperf(df, \"double-x\"), '->c', linewidth='1', markersize='3', label='struct Point \\{double x, y, z;\\}')\n",
    "plt.plot(xf, getperf(df, \"float-x\"), '--or', linewidth='1', markersize='3', label='struct Point \\{float x, y, z;\\}')\n",
    "plt.xscale(\"log\")\n",
    "plt.ylim(0,10)\n",
    "plt.xlabel(\"Array size\", fontsize=15)\n",
    "plt.ylabel(\"Speed up relative to std::sort\", fontsize=15)\n",
    "plt.title('Sort by x-coordinate', fontsize=15)\n",
    "plt.legend()\n",
    "\n",
    "plt.subplot(2, 2, 2)\n",
    "plt.plot(xd, getperf(df, \"double-taxicab\"), '->c', linewidth='1', markersize='3', label='struct Point \\{double x, y, z;\\}')\n",
    "plt.plot(xf, getperf(df, \"float-taxicab\"), '--or', linewidth='1', markersize='3', label='struct Point \\{float x, y, z;\\}')\n",
    "plt.xscale(\"log\")\n",
    "plt.ylim(0,10)\n",
    "plt.xlabel(\"Array size\", fontsize=15)\n",
    "plt.ylabel(\"Speed up relative to std::sort\", fontsize=15)\n",
    "plt.title('Sort by manhanttan distance', fontsize=15)\n",
    "plt.legend()\n",
    "\n",
    "plt.subplot(2, 2, 3)\n",
    "plt.plot(xd, getperf(df, \"double-euclidean\"), '->c', linewidth='1', markersize='3', label='struct Point \\{double x, y, z;\\}')\n",
    "plt.plot(xf, getperf(df, \"float-euclidean\"), '--or', linewidth='1', markersize='3', label='struct Point \\{float x, y, z;\\}')\n",
    "plt.xscale(\"log\")\n",
    "plt.ylim(0,10)\n",
    "plt.xlabel(\"Array size\", fontsize=15)\n",
    "plt.ylabel(\"Speed up relative to std::sort\", fontsize=15)\n",
    "plt.title('Sort by Euclidean distance', fontsize=15)\n",
    "plt.legend()\n",
    "\n",
    "plt.subplot(2, 2, 4)\n",
    "plt.plot(xd, getperf(df, \"double-chebyshev\"), '->c', linewidth='1', markersize='3', label='struct Point \\{double x, y, z;\\}')\n",
    "plt.plot(xf, getperf(df, \"float-chebyshev\"), '--or', linewidth='1', markersize='3', label='struct Point \\{float x, y, z;\\}')\n",
    "plt.xscale(\"log\")\n",
    "plt.ylim(0,10)\n",
    "plt.xlabel(\"Array size\", fontsize=15)\n",
    "plt.ylabel(\"Speed up relative to std::sort\", fontsize=15)\n",
    "plt.title('Sort by Chebyshev distance', fontsize=15,pad=-14)\n",
    "plt.legend()\n",
    "fig.savefig('object_qsort-perf.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "c5fda26c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1b7918fc040>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 175612 characters]\n",
      "text/plain": [
       "<Figure size 900x900 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def getsimdcol(df, metric):\n",
    "    simdm = \"simdobjsort<Point3D<\" + metric + \">>\"\n",
    "    t1 = df[df['name'].str.contains(simdm)][\"real_time\"]\n",
    "    return np.array(t1)\n",
    "\n",
    "def getscalarcol(df, metric):\n",
    "    simdm = \"scalarobjsort<Point3D<\" + metric + \">>\"\n",
    "    t1 = df[df['name'].str.contains(simdm)][\"real_time\"]\n",
    "    return np.array(t1)\n",
    "\n",
    "xf = df[df['name'].str.contains(\"scalarobjsort<Point3D<float-x>>\")][\"arraysize\"]\n",
    "xd = df[df['name'].str.contains(\"scalarobjsort<Point3D<double-x>>\")][\"arraysize\"]\n",
    "\n",
    "fig = plt.figure()\n",
    "plt.rcParams['figure.figsize'] = [9,9]\n",
    "plt.subplot(2, 2, 1)\n",
    "plt.plot(xd, getsimdcol(df, \"double-x\"), '-', linewidth='1', label='simd double, x')\n",
    "plt.plot(xd, getscalarcol(df, \"double-x\"), '-', linewidth='1', label='double, x')\n",
    "plt.plot(xd, getsimdcol(df, \"float-x\"), '--', linewidth='1', label='simd float, x')\n",
    "plt.plot(xd, getscalarcol(df, \"float-x\"), '--', linewidth='1', label='float, x')\n",
    "\n",
    "plt.xlabel(\"size of array in Bytes\")\n",
    "plt.ylabel(\"Speed up relative to std::sort\")\n",
    "plt.legend()\n",
    "\n",
    "plt.subplot(2, 2, 2)\n",
    "plt.plot(xd, getsimdcol(df, \"double-taxicab\"), '-', linewidth='1', label='simd double, taxi')\n",
    "plt.plot(xd, getscalarcol(df, \"double-taxicab\"), '-', linewidth='1', label='double, taxi')\n",
    "plt.plot(xd, getsimdcol(df, \"float-taxicab\"), '--', linewidth='1', label='simd float, taxi')\n",
    "plt.plot(xd, getscalarcol(df, \"float-taxicab\"), '--', linewidth='1', label='float, taxi')\n",
    "plt.xscale(\"log\")\n",
    "plt.yscale(\"log\")\n",
    "plt.xlabel(\"size of array in Bytes\")\n",
    "plt.ylabel(\"Speed up relative to std::sort\")\n",
    "plt.legend()\n",
    "\n",
    "plt.subplot(2, 2, 3)\n",
    "plt.plot(xd, getsimdcol(df, \"double-euclidean\"), '-', linewidth='1', label='simd double, euc')\n",
    "plt.plot(xd, getscalarcol(df, \"double-euclidean\"), '-', linewidth='1', label='double, euc')\n",
    "plt.plot(xd, getsimdcol(df, \"float-euclidean\"), '--', linewidth='1', label='simd float, euc')\n",
    "plt.plot(xd, getscalarcol(df, \"float-euclidean\"), '--', linewidth='1', label='float, euc')\n",
    "plt.xscale(\"log\")\n",
    "plt.yscale(\"log\")\n",
    "plt.xlabel(\"size of array in Bytes\")\n",
    "plt.ylabel(\"Speed up relative to std::sort\")\n",
    "plt.legend()\n",
    "\n",
    "plt.subplot(2, 2, 4)\n",
    "plt.plot(xd, getsimdcol(df, \"double-chebyshev\"), '-', linewidth='1', label='simd double, chebyshev')\n",
    "plt.plot(xd, getscalarcol(df, \"double-chebyshev\"), '-', linewidth='1', label='double, chebyshev')\n",
    "plt.plot(xd, getsimdcol(df, \"float-chebyshev\"), '--', linewidth='1', label='simd float, chebyshev')\n",
    "plt.plot(xd, getscalarcol(df, \"float-chebyshev\"), '--', linewidth='1', label='float, chebyshev')\n",
    "plt.xlabel(\"size of array in Bytes\")\n",
    "plt.ylabel(\"Speed up relative to std::sort\")\n",
    "plt.legend()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
