diff --git a/interpreters/README.md b/interpreters/README.md index 26f2efe..7cf127e 100644 --- a/interpreters/README.md +++ b/interpreters/README.md @@ -1,21 +1,40 @@ # Interpreters +## Results +![results](result.png) + +### Observations +- Functions w/o Numpy in PyPy run **much faster**. JIT compilation optimizes the function's code and runs compiled versions of them $\Rightarrow$ improvement in time +- Entire file evaluation for PyPy takes **a bit longer**. This may be a drawback of JIT optimization +- [PyPy with Numpy is slow](https://stackoverflow.com/questions/42536308/why-is-pypy-slower-for-adding-numpy-arrays). Reason: + - Numpy is written in C + - PyPy's JIT compilation is not compatible with C + - Extra conversion is required (takes time) +- Numpy functions don't give a good improvement in perfomance. Possibly because the code uses classic Python loops instead of numpy vectorisation. + ## Tested interpreters - CPython 3.9 - CPython 3.11 -- PyPy 3.9 - -**Table of evaluation times in seconds** - -![enter image description here](table.png) - +- PyPy 3.9 latest +- Pyodide (did not test full file because it only runs in a browser) +- Xeus (again no full file) +## Failed to test +- PyPy 3.9 v5.7 + - couldn't install numpy `Ignoring ensurepip failure: pip 9.0.1 requires SSL/TLS` + - error when testing with types: +```python +invalid syntax --> image: list[list[int]] = [[0 for i in range(qpoints)] for j in range(ppoints)] +``` +- Jython (dependencies issues) ## Testing Code -- File for testing function times: `test.py` +- Tested functions code is in `./test_funcs` package +- File for testing function times: `test_func_only.py` - Files for entire evaluation testing: `test_full_{func}.py` -- Bash script `test_full.sh` +- Bash script: `test_full.sh` +- Analysis file: `analyse.ipynb` -Three realisations of mandelbrot functions tested: +### Realisations of mandelbrot functions tested: ```python def linspace(start, stop, n): if n == 1: diff --git a/interpreters/analyse.ipynb b/interpreters/analyse.ipynb new file mode 100644 index 0000000..d0afbb6 --- /dev/null +++ b/interpreters/analyse.ipynb @@ -0,0 +1,1620 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import os, sys\n", + "import numpy as np\n", + "import pandas as pd\n", + "import json\n", + "pd.options.mode.chained_assignment = None\n", + "\n", + "import plotly.graph_objects as go\n", + "import plotly.io as pio\n", + "import plotly.express as px\n", + "from plotly.subplots import make_subplots\n", + "from unicodeit import replace as tex_to_unis\n", + "# sys.path.append(\"C:/Users/rurur/Desktop/p/python/plotly\")\n", + "# import plotly_setup" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CPython-3.11.txt CPython-3.11_full.txt CPython-3.9.txt CPython-3.9_full.txt Pyodide.txt PyPy-3.9-v7.3.13.txt PyPy-3.9-v7.3.13_full.txt Xeus.txt\n", + "PyPy-3.9-v7.3.13 CPython-3.9 CPython-3.11 Pyodide Xeus\n" + ] + } + ], + "source": [ + "result_files = os.listdir(\"./results\")\n", + "result_titles = sorted(set([f.rstrip(\"full_.txt\") for f in result_files]))\n", + "result_titles[0], result_titles[2] = result_titles[2], result_titles[0]\n", + "print(*result_files)\n", + "print(*result_titles)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "df = pd.DataFrame()\n", + "funcs = [\"time_with_types\", \"time_no_types\", \"time_np\"]\n", + "funcs_titles = [f.lstrip(\"time_\") for f in funcs]\n", + "funcs_titles[-1] = \"numpy\"\n", + "for rtitle in result_titles:\n", + " with open(f\"results/{rtitle}.txt\", \"r\", encoding=\"utf-8\") as f:\n", + " result = json.load(f)\n", + " result_df = pd.DataFrame(dict(\n", + " interpreter=result[\"interpreter\"],\n", + " time=[result[func] for func in funcs],\n", + " funcs=funcs_titles,\n", + " test_mode=\"func\"\n", + " ))\n", + " df = pd.concat([df, result_df], ignore_index=True)\n", + "\n", + " fname_full_time = f\"{rtitle}_full.txt\"\n", + " if fname_full_time in result_files:\n", + " with open(f\"results/{fname_full_time}\", \"r\", encoding=\"utf-8\") as f:\n", + " times = [float(line) for line in f.readlines()]\n", + " result_df = pd.DataFrame(dict(\n", + " interpreter=result[\"interpreter\"],\n", + " time=times,\n", + " funcs=funcs_titles,\n", + " test_mode=\"full\"\n", + " ))\n", + " df = pd.concat([df, pd.DataFrame(result_df)], ignore_index=True)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
interpretertimefuncstest_mode
0PyPy-3.9-v7.3.130.099364with_typesfunc
1PyPy-3.9-v7.3.130.109924no_typesfunc
2PyPy-3.9-v7.3.133.676712numpyfunc
3PyPy-3.9-v7.3.135.319000with_typesfull
4PyPy-3.9-v7.3.133.638000no_typesfull
5PyPy-3.9-v7.3.1314.639000numpyfull
6CPython-3.91.445288with_typesfunc
7CPython-3.91.476920no_typesfunc
8CPython-3.91.407270numpyfunc
9CPython-3.92.242000with_typesfull
10CPython-3.91.502000no_typesfull
11CPython-3.91.986000numpyfull
12CPython-3.110.820678with_typesfunc
13CPython-3.110.856216no_typesfunc
14CPython-3.111.202004numpyfunc
15CPython-3.111.630000with_typesfull
16CPython-3.111.166000no_typesfull
17CPython-3.111.675000numpyfull
18piodide1.785000with_typesfunc
19piodide1.681000no_typesfunc
20piodide2.833000numpyfunc
21Xeus1.155519with_typesfunc
22Xeus1.038669no_typesfunc
23Xeus1.272793numpyfunc
\n", + "
" + ], + "text/plain": [ + " interpreter time funcs test_mode\n", + "0 PyPy-3.9-v7.3.13 0.099364 with_types func\n", + "1 PyPy-3.9-v7.3.13 0.109924 no_types func\n", + "2 PyPy-3.9-v7.3.13 3.676712 numpy func\n", + "3 PyPy-3.9-v7.3.13 5.319000 with_types full\n", + "4 PyPy-3.9-v7.3.13 3.638000 no_types full\n", + "5 PyPy-3.9-v7.3.13 14.639000 numpy full\n", + "6 CPython-3.9 1.445288 with_types func\n", + "7 CPython-3.9 1.476920 no_types func\n", + "8 CPython-3.9 1.407270 numpy func\n", + "9 CPython-3.9 2.242000 with_types full\n", + "10 CPython-3.9 1.502000 no_types full\n", + "11 CPython-3.9 1.986000 numpy full\n", + "12 CPython-3.11 0.820678 with_types func\n", + "13 CPython-3.11 0.856216 no_types func\n", + "14 CPython-3.11 1.202004 numpy func\n", + "15 CPython-3.11 1.630000 with_types full\n", + "16 CPython-3.11 1.166000 no_types full\n", + "17 CPython-3.11 1.675000 numpy full\n", + "18 piodide 1.785000 with_types func\n", + "19 piodide 1.681000 no_types func\n", + "20 piodide 2.833000 numpy func\n", + "21 Xeus 1.155519 with_types func\n", + "22 Xeus 1.038669 no_types func\n", + "23 Xeus 1.272793 numpy func" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.plotly.v1+json": { + "config": { + "plotlyServerURL": "https://plotly.com" + }, + "data": [ + { + "alignmentgroup": "True", + "hovertemplate": "test_mode=func
funcs=with_types
interpreter=%{x}
Time, s=%{y}", + "legendgroup": "", + "marker": { + "color": "#636efa", + "pattern": { + "shape": "" + } + }, + "name": "", + "offsetgroup": "", + "orientation": "v", + "showlegend": false, + "textposition": "auto", + "type": "bar", + "x": [ + "PyPy-3.9-v7.3.13", + "CPython-3.9", + "CPython-3.11", + "piodide", + "Xeus" + ], + "xaxis": "x4", + "y": [ + 0.099363702, + 1.445288, + 0.8206779, + 1.785, + 1.1555191 + ], + "yaxis": "y4" + }, + { + "alignmentgroup": "True", + "hovertemplate": "test_mode=func
funcs=no_types
interpreter=%{x}
Time, s=%{y}", + "legendgroup": "", + "marker": { + "color": "#636efa", + "pattern": { + "shape": "" + } + }, + "name": "", + "offsetgroup": "", + "orientation": "v", + "showlegend": false, + "textposition": "auto", + "type": "bar", + "x": [ + "PyPy-3.9-v7.3.13", + "CPython-3.9", + "CPython-3.11", + "piodide", + "Xeus" + ], + "xaxis": "x5", + "y": [ + 0.109923603, + 1.4769202, + 0.8562159, + 1.681, + 1.0386694 + ], + "yaxis": "y5" + }, + { + "alignmentgroup": "True", + "hovertemplate": "test_mode=func
funcs=numpy
interpreter=%{x}
Time, s=%{y}", + "legendgroup": "", + "marker": { + "color": "#636efa", + "pattern": { + "shape": "" + } + }, + "name": "", + "offsetgroup": "", + "orientation": "v", + "showlegend": false, + "textposition": "auto", + "type": "bar", + "x": [ + "PyPy-3.9-v7.3.13", + "CPython-3.9", + "CPython-3.11", + "piodide", + "Xeus" + ], + "xaxis": "x6", + "y": [ + 3.676712179, + 1.4072699, + 1.2020039, + 2.833, + 1.2727932 + ], + "yaxis": "y6" + }, + { + "alignmentgroup": "True", + "hovertemplate": "test_mode=full
funcs=with_types
interpreter=%{x}
Time, s=%{y}", + "legendgroup": "", + "marker": { + "color": "#636efa", + "pattern": { + "shape": "" + } + }, + "name": "", + "offsetgroup": "", + "orientation": "v", + "showlegend": false, + "textposition": "auto", + "type": "bar", + "x": [ + "PyPy-3.9-v7.3.13", + "CPython-3.9", + "CPython-3.11" + ], + "xaxis": "x", + "y": [ + 5.319, + 2.242, + 1.63 + ], + "yaxis": "y" + }, + { + "alignmentgroup": "True", + "hovertemplate": "test_mode=full
funcs=no_types
interpreter=%{x}
Time, s=%{y}", + "legendgroup": "", + "marker": { + "color": "#636efa", + "pattern": { + "shape": "" + } + }, + "name": "", + "offsetgroup": "", + "orientation": "v", + "showlegend": false, + "textposition": "auto", + "type": "bar", + "x": [ + "PyPy-3.9-v7.3.13", + "CPython-3.9", + "CPython-3.11" + ], + "xaxis": "x2", + "y": [ + 3.638, + 1.502, + 1.166 + ], + "yaxis": "y2" + }, + { + "alignmentgroup": "True", + "hovertemplate": "test_mode=full
funcs=numpy
interpreter=%{x}
Time, s=%{y}", + "legendgroup": "", + "marker": { + "color": "#636efa", + "pattern": { + "shape": "" + } + }, + "name": "", + "offsetgroup": "", + "orientation": "v", + "showlegend": false, + "textposition": "auto", + "type": "bar", + "x": [ + "PyPy-3.9-v7.3.13", + "CPython-3.9", + "CPython-3.11" + ], + "xaxis": "x3", + "y": [ + 14.639, + 1.986, + 1.675 + ], + "yaxis": "y3" + } + ], + "layout": { + "annotations": [ + { + "font": {}, + "showarrow": false, + "text": "with_types", + "x": 0.15333333333333332, + "xanchor": "center", + "xref": "paper", + "y": 1, + "yanchor": "bottom", + "yref": "paper" + }, + { + "font": {}, + "showarrow": false, + "text": "no_types", + "x": 0.49, + "xanchor": "center", + "xref": "paper", + "y": 1, + "yanchor": "bottom", + "yref": "paper" + }, + { + "font": {}, + "showarrow": false, + "text": "numpy", + "x": 0.8266666666666667, + "xanchor": "center", + "xref": "paper", + "y": 1, + "yanchor": "bottom", + "yref": "paper" + }, + { + "font": {}, + "showarrow": false, + "text": "full", + "textangle": 90, + "x": 0.98, + "xanchor": "left", + "xref": "paper", + "y": 0.2125, + "yanchor": "middle", + "yref": "paper" + }, + { + "font": {}, + "showarrow": false, + "text": "func", + "textangle": 90, + "x": 0.98, + "xanchor": "left", + "xref": "paper", + "y": 0.7875, + "yanchor": "middle", + "yref": "paper" + } + ], + "barmode": "relative", + "font": { + "size": 13 + }, + "height": 620, + "legend": { + "tracegroupgap": 0 + }, + "margin": { + "b": 10, + "t": 20 + }, + "template": { + "data": { + "bar": [ + { + "error_x": { + "color": "#2a3f5f" + }, + "error_y": { + "color": "#2a3f5f" + }, + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "bar" + } + ], + "barpolar": [ + { + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "barpolar" + } + ], + "carpet": [ + { + "aaxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "baxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "type": "carpet" + } + ], + "choropleth": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "choropleth" + } + ], + "contour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "contour" + } + ], + "contourcarpet": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "contourcarpet" + } + ], + "heatmap": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmap" + } + ], + "heatmapgl": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmapgl" + } + ], + "histogram": [ + { + "marker": { + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "histogram" + } + ], + "histogram2d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2d" + } + ], + "histogram2dcontour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2dcontour" + } + ], + "mesh3d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "mesh3d" + } + ], + "parcoords": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "parcoords" + } + ], + "pie": [ + { + "automargin": true, + "type": "pie" + } + ], + "scatter": [ + { + "fillpattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + }, + "type": "scatter" + } + ], + "scatter3d": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatter3d" + } + ], + "scattercarpet": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattercarpet" + } + ], + "scattergeo": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergeo" + } + ], + "scattergl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergl" + } + ], + "scattermapbox": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermapbox" + } + ], + "scatterpolar": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolar" + } + ], + "scatterpolargl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolargl" + } + ], + "scatterternary": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterternary" + } + ], + "surface": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "surface" + } + ], + "table": [ + { + "cells": { + "fill": { + "color": "#EBF0F8" + }, + "line": { + "color": "white" + } + }, + "header": { + "fill": { + "color": "#C8D4E3" + }, + "line": { + "color": "white" + } + }, + "type": "table" + } + ] + }, + "layout": { + "annotationdefaults": { + "arrowcolor": "#2a3f5f", + "arrowhead": 0, + "arrowwidth": 1 + }, + "autotypenumbers": "strict", + "coloraxis": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "colorscale": { + "diverging": [ + [ + 0, + "#8e0152" + ], + [ + 0.1, + "#c51b7d" + ], + [ + 0.2, + "#de77ae" + ], + [ + 0.3, + "#f1b6da" + ], + [ + 0.4, + "#fde0ef" + ], + [ + 0.5, + "#f7f7f7" + ], + [ + 0.6, + "#e6f5d0" + ], + [ + 0.7, + "#b8e186" + ], + [ + 0.8, + "#7fbc41" + ], + [ + 0.9, + "#4d9221" + ], + [ + 1, + "#276419" + ] + ], + "sequential": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "sequentialminus": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ] + }, + "colorway": [ + "#636efa", + "#EF553B", + "#00cc96", + "#ab63fa", + "#FFA15A", + "#19d3f3", + "#FF6692", + "#B6E880", + "#FF97FF", + "#FECB52" + ], + "font": { + "color": "#2a3f5f" + }, + "geo": { + "bgcolor": "white", + "lakecolor": "white", + "landcolor": "#E5ECF6", + "showlakes": true, + "showland": true, + "subunitcolor": "white" + }, + "hoverlabel": { + "align": "left" + }, + "hovermode": "closest", + "mapbox": { + "style": "light" + }, + "paper_bgcolor": "white", + "plot_bgcolor": "#E5ECF6", + "polar": { + "angularaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "radialaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "scene": { + "xaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "yaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "zaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + } + }, + "shapedefaults": { + "line": { + "color": "#2a3f5f" + } + }, + "ternary": { + "aaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "baxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "caxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "title": { + "x": 0.05 + }, + "xaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + }, + "yaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + } + } + }, + "width": 800, + "xaxis": { + "anchor": "y", + "domain": [ + 0, + 0.30666666666666664 + ], + "showticklabels": true, + "title": {} + }, + "xaxis2": { + "anchor": "y2", + "domain": [ + 0.33666666666666667, + 0.6433333333333333 + ], + "showticklabels": true, + "title": {} + }, + "xaxis3": { + "anchor": "y3", + "domain": [ + 0.6733333333333333, + 0.98 + ], + "showticklabels": true, + "title": {} + }, + "xaxis4": { + "anchor": "y4", + "domain": [ + 0, + 0.30666666666666664 + ], + "showticklabels": true, + "title": {} + }, + "xaxis5": { + "anchor": "y5", + "domain": [ + 0.33666666666666667, + 0.6433333333333333 + ], + "showticklabels": true, + "title": {} + }, + "xaxis6": { + "anchor": "y6", + "domain": [ + 0.6733333333333333, + 0.98 + ], + "showticklabels": true, + "title": {} + }, + "yaxis": { + "anchor": "x", + "domain": [ + 0, + 0.425 + ], + "range": [ + 0, + 16 + ], + "title": { + "text": "Time, s" + } + }, + "yaxis2": { + "anchor": "x2", + "domain": [ + 0, + 0.425 + ], + "range": [ + 0, + 16 + ], + "showticklabels": false + }, + "yaxis3": { + "anchor": "x3", + "domain": [ + 0, + 0.425 + ], + "range": [ + 0, + 16 + ], + "showticklabels": false + }, + "yaxis4": { + "anchor": "x4", + "domain": [ + 0.575, + 1 + ], + "range": [ + 0, + 4 + ], + "title": { + "text": "Time, s" + } + }, + "yaxis5": { + "anchor": "x5", + "domain": [ + 0.575, + 1 + ], + "range": [ + 0, + 4 + ], + "showticklabels": false + }, + "yaxis6": { + "anchor": "x6", + "domain": [ + 0.575, + 1 + ], + "range": [ + 0, + 4 + ], + "showticklabels": false + } + } + } + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "fig = px.bar(df,\n", + " x=\"interpreter\",\n", + " y=\"time\",\n", + " facet_col=\"funcs\",\n", + " facet_row=\"test_mode\",\n", + " facet_row_spacing=0.15,\n", + " facet_col_spacing=0.03,\n", + " labels=dict(time=\"Time, s\")\n", + ").update_layout(\n", + " width=800, height=620,\n", + " margin=dict(b=10, t=20),\n", + " # title=dict(text=\"Results of Testing\"),\n", + " font=dict(size=13)\n", + ").update_yaxes(\n", + " matches=None,\n", + ").update_yaxes(\n", + " # showticklabels=True,\n", + " row=1,\n", + " range=(0, 16)\n", + ").update_yaxes(\n", + " # showticklabels=True,\n", + " row=2,\n", + " range=(0, 4)\n", + ").update_xaxes(\n", + " matches=None,\n", + " showticklabels=True,\n", + " title=None\n", + ").for_each_annotation(\n", + " lambda a: a.update(text=a.text.split(\"=\")[-1])\n", + ")\n", + "fig.write_image(\"result.png\", scale=2.5)\n", + "# fig.layout.yaxis.matches = 'y'\n", + "# fig.layout.yaxis1.matches = 'y1'\n", + "fig.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.10" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/interpreters/result.png b/interpreters/result.png new file mode 100644 index 0000000..1a2379f Binary files /dev/null and b/interpreters/result.png differ diff --git a/interpreters/results/CPython-3.11.txt b/interpreters/results/CPython-3.11.txt index 0480efe..b2940e8 100644 --- a/interpreters/results/CPython-3.11.txt +++ b/interpreters/results/CPython-3.11.txt @@ -1,4 +1,6 @@ -interpreter: CPython-3.11 -time in seconds: -with types no types with numpy -1.001602 1.047993 1.322597 \ No newline at end of file +{ + "interpreter": "CPython-3.11", + "time_with_types": 0.8206779, + "time_no_types": 0.8562159, + "time_np": 1.2020039 +} diff --git a/interpreters/results/CPython-3.11_full.txt b/interpreters/results/CPython-3.11_full.txt index 03cef69..4631303 100644 --- a/interpreters/results/CPython-3.11_full.txt +++ b/interpreters/results/CPython-3.11_full.txt @@ -1,12 +1,3 @@ - -real 0m1.669s -user 0m0.012s -sys 0m0.055s - -real 0m1.197s -user 0m0.004s -sys 0m0.009s - -real 0m2.274s -user 0m0.014s -sys 0m0.000s +1.630 +1.166 +1.675 diff --git a/interpreters/results/CPython-3.9.txt b/interpreters/results/CPython-3.9.txt index c464600..a25ed42 100644 --- a/interpreters/results/CPython-3.9.txt +++ b/interpreters/results/CPython-3.9.txt @@ -1,4 +1,6 @@ -interpreter: CPython-3.9 -time in seconds: -with types no types with numpy -1.377455 1.345244 1.437867 \ No newline at end of file +{ + "interpreter": "CPython-3.9", + "time_with_types": 1.445288, + "time_no_types": 1.4769202, + "time_np": 1.4072699 +} diff --git a/interpreters/results/CPython-3.9_full.txt b/interpreters/results/CPython-3.9_full.txt index 978522a..2f859a5 100644 --- a/interpreters/results/CPython-3.9_full.txt +++ b/interpreters/results/CPython-3.9_full.txt @@ -1,12 +1,3 @@ - -real 0m2.180s -user 0m0.008s -sys 0m0.061s - -real 0m1.696s -user 0m0.013s -sys 0m0.000s - -real 0m2.447s -user 0m0.008s -sys 0m0.004s +2.242 +1.502 +1.986 diff --git a/interpreters/results/Jython_error.txt b/interpreters/results/Jython_error.txt deleted file mode 100644 index b9367ac..0000000 --- a/interpreters/results/Jython_error.txt +++ /dev/null @@ -1,11 +0,0 @@ -Traceback (most recent call last): - File "test_full_with_types.py", line 1, in - from pure_with_types import mandelbrot_with_types - File "/mnt/c/Users/rurur/Desktop/p/python/advanced_python/advanced-python-homework-2023/interpreters/pure_with_types.py", line 4 - pmin: float = -2.5, - ^ -SyntaxError: mismatched input ':' expecting RPAREN - -real 0m5.653s -user 0m15.313s -sys 0m0.617s diff --git a/interpreters/results/Jython_full.txt b/interpreters/results/Jython_full.txt deleted file mode 100644 index dff3fdf..0000000 --- a/interpreters/results/Jython_full.txt +++ /dev/null @@ -1,11 +0,0 @@ -Traceback (most recent call last): - File "test_full_with_types.py", line 1, in - from pure_with_types import mandelbrot_with_types - File "/mnt/c/Users/rurur/Desktop/p/python/advanced_python/advanced-python-homework-2023/interpreters/pure_with_types.py", line 4 - pmin: float = -2.5, - ^ -SyntaxError: mismatched input ':' expecting RPAREN - -real 0m4.948s -user 0m14.826s -sys 0m0.715s diff --git a/interpreters/results/PyPy-3.9-v7.3.13.txt b/interpreters/results/PyPy-3.9-v7.3.13.txt index b7dde11..34d3b2e 100644 --- a/interpreters/results/PyPy-3.9-v7.3.13.txt +++ b/interpreters/results/PyPy-3.9-v7.3.13.txt @@ -1,4 +1,6 @@ -interpreter: PyPy-3.9-v7.3.13 -time in seconds: -with types no types with numpy -0.099699 0.093644 3.830524 \ No newline at end of file +{ + "interpreter": "PyPy-3.9-v7.3.13", + "time_with_types": 0.099363702, + "time_no_types": 0.109923603, + "time_np": 3.676712179 +} diff --git a/interpreters/results/PyPy-3.9-v7.3.13_full.txt b/interpreters/results/PyPy-3.9-v7.3.13_full.txt index bb72907..2e58523 100644 --- a/interpreters/results/PyPy-3.9-v7.3.13_full.txt +++ b/interpreters/results/PyPy-3.9-v7.3.13_full.txt @@ -1,12 +1,3 @@ - -real 0m5.456s -user 0m0.128s -sys 0m0.459s - -real 0m3.527s -user 0m0.107s -sys 0m0.492s - -real 0m15.416s -user 0m4.836s -sys 0m1.698s +5.319 +3.638 +14.639 diff --git a/interpreters/results/Pyodide.txt b/interpreters/results/Pyodide.txt new file mode 100644 index 0000000..ad8eca3 --- /dev/null +++ b/interpreters/results/Pyodide.txt @@ -0,0 +1,6 @@ +{ + "interpreter": "piodide", + "time_with_types": 1.785, + "time_no_types": 1.681, + "time_np": 2.833 +} \ No newline at end of file diff --git a/interpreters/results/Xeus.txt b/interpreters/results/Xeus.txt new file mode 100644 index 0000000..39ef077 --- /dev/null +++ b/interpreters/results/Xeus.txt @@ -0,0 +1,6 @@ +{ + "interpreter": "Xeus", + "time_with_types": 1.1555191, + "time_no_types": 1.0386694, + "time_np": 1.2727932 +} \ No newline at end of file diff --git a/interpreters/test.py b/interpreters/test.py deleted file mode 100644 index 602579b..0000000 --- a/interpreters/test.py +++ /dev/null @@ -1,43 +0,0 @@ -import time -import sys -from pure_with_types import mandelbrot_with_types -from pure_no_types import mandelbrot_no_types -from np_extended import mandelbrot_np - - -def test(function): - tic = time.perf_counter_ns() - image = function() - toc = time.perf_counter_ns() - return (toc - tic) / 1e9 - -def try_func(function): - try: - time = test(function) - except Exception as e: - raise e - return time - -def main(arg): - interpreter = arg[1] - - time_with_types = "err" - time_no_types = "err" - time_np = "err" - - time_with_types = try_func(mandelbrot_with_types) - time_no_types = try_func(mandelbrot_no_types) - time_np = try_func(mandelbrot_np) - - response = f"interpreter: {interpreter}\n"\ - "time in seconds:\n"\ - "with types\tno types\twith numpy\n"\ - f"err\t{time_no_types:.6f}\t{time_np:.6f}" - # response = "{:.6f} {:.6f}".format(time_no_types, time_np) - print(response) - with open("results/{}.txt".format(interpreter), "w", encoding="utf8") as f: - f.write(response) - - -if __name__ == "__main__": - main(sys.argv) diff --git a/interpreters/test_full.sh b/interpreters/test_full.sh index 9ec5dda..095c423 100644 --- a/interpreters/test_full.sh +++ b/interpreters/test_full.sh @@ -2,11 +2,11 @@ interpreterCmd=$1; interpreterTitle=$2; - +TIMEFORMAT=%R { time $interpreterCmd test_full_with_types.py && time $interpreterCmd test_full_no_types.py && time $interpreterCmd test_full_np.py; } 2> results/${interpreterTitle}_full.txt; -$interpreterCmd test.py $interpreterTitle; +$interpreterCmd test_func_only.py $interpreterTitle; diff --git a/interpreters/test_full_no_types.py b/interpreters/test_full_no_types.py index 5ab5d83..5ccc32d 100644 --- a/interpreters/test_full_no_types.py +++ b/interpreters/test_full_no_types.py @@ -1,3 +1,3 @@ -from pure_no_types import mandelbrot_no_types +from test_funcs.pure_no_types import mandelbrot_no_types mandelbrot_no_types() diff --git a/interpreters/test_full_np.py b/interpreters/test_full_np.py index 16277b6..441dcf8 100644 --- a/interpreters/test_full_np.py +++ b/interpreters/test_full_np.py @@ -1,3 +1,3 @@ -from np_extended import mandelbrot_np +from test_funcs.np_extended import mandelbrot_np mandelbrot_np() diff --git a/interpreters/test_full_with_types.py b/interpreters/test_full_with_types.py index 1757580..5911739 100644 --- a/interpreters/test_full_with_types.py +++ b/interpreters/test_full_with_types.py @@ -1,3 +1,3 @@ -from pure_with_types import mandelbrot_with_types +from test_funcs.pure_with_types import mandelbrot_with_types mandelbrot_with_types() diff --git a/interpreters/test_func_only.py b/interpreters/test_func_only.py new file mode 100644 index 0000000..737a87d --- /dev/null +++ b/interpreters/test_func_only.py @@ -0,0 +1,49 @@ +import time +import json +import sys, os +# sys.path.append(os.path.abspath("./test_files")) + +from test_funcs.pure_with_types import mandelbrot_with_types +from test_funcs.pure_no_types import mandelbrot_no_types +# from test_funcs.np_extended import mandelbrot_np + +def test(function): + tic = time.perf_counter_ns() + image = function() + toc = time.perf_counter_ns() + return (toc - tic) / 1e9 + +def try_func(function): + try: + time = test(function) + except Exception as e: + raise e + return time + +def main(arg): + interpreter = arg[1] + + time_with_types = "err" + time_no_types = "err" + time_np = "err" + + time_with_types = try_func(mandelbrot_with_types) + time_no_types = try_func(mandelbrot_no_types) + # time_np = try_func(mandelbrot_np) + + response = dict( + interpreter=interpreter, + time_with_types=time_with_types, + time_no_types=time_no_types, + # time_np=time_np + ) + result_string = json.dumps(response, indent=4, ensure_ascii=False) + # f = open("results/{}.txt".format(interpreter), "w", encoding="utf8") + # print(result_string, file=f) + # f.close() + + print(result_string) + + +if __name__ == "__main__": + main(sys.argv) diff --git a/interpreters/test_funcs/__init__.py b/interpreters/test_funcs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/interpreters/linspace.py b/interpreters/test_funcs/linspace.py similarity index 100% rename from interpreters/linspace.py rename to interpreters/test_funcs/linspace.py diff --git a/interpreters/np_extended.py b/interpreters/test_funcs/np_extended.py similarity index 100% rename from interpreters/np_extended.py rename to interpreters/test_funcs/np_extended.py diff --git a/interpreters/pure_no_types.py b/interpreters/test_funcs/pure_no_types.py similarity index 95% rename from interpreters/pure_no_types.py rename to interpreters/test_funcs/pure_no_types.py index d919337..c1c6a57 100644 --- a/interpreters/pure_no_types.py +++ b/interpreters/test_funcs/pure_no_types.py @@ -1,4 +1,4 @@ -from linspace import linspace +from .linspace import linspace def mandelbrot_no_types( pmin=-2.5, diff --git a/interpreters/pure_with_types.py b/interpreters/test_funcs/pure_with_types.py similarity index 95% rename from interpreters/pure_with_types.py rename to interpreters/test_funcs/pure_with_types.py index 9e667df..7545cba 100644 --- a/interpreters/pure_with_types.py +++ b/interpreters/test_funcs/pure_with_types.py @@ -1,4 +1,4 @@ -from linspace import linspace +from .linspace import linspace def mandelbrot_with_types( pmin: float = -2.5,