{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## SimplePlots.jl Speed Tests\n", "\n", "---\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n" ], "text/plain": [ "HTML{String}(\" \\n\")" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " 1.478263 seconds (3.18 M allocations: 162.722 MiB, 2.37% gc time)\n" ] } ], "source": [ "@time using SimplePlots" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 1.638591 seconds (3.53 M allocations: 172.899 MiB, 9.20% gc time)\n" ] }, { "data": { "text/html": [ "
\n", " \n" ], "text/plain": [ "HTML{String}(\"
\\n \\n\")" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function foo()\n", " scatter(\n", " rand(10), label=\"Scatter\", color=4,\n", " xlabel=\"x\", markersize=6\n", " )\n", "\n", " ylabel!(\"y\")\n", "\n", " cur_x = 10 .^ (0:0.1:1)\n", " cur_y = rand(0.25:0.05:0.75, length(cur_x))\n", "\n", " plot!(cur_x, cur_y, label=\"Plot\", color=3, title=\"Example\")\n", "\n", " hline!([1,3] ./ 4, color=2)\n", " vline!(5, linewidth=4, alpha=0.4, linestyle=:dash)\n", "\n", " plot!(xlim=(1,15))\n", "\n", " ylims!(0,1)\n", " xscale!(:log10)\n", "end\n", "\n", "@time foo()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", " y\n", "
\n", "
\n", " 5\n", "
\n", "\n", "
\n", "
\n", "
\n", " t\n", "
\n", "
\n", "
\n", "
\n", " title1\n", "
\n", "
\n", " title2\n", "
\n", "
\n", " title3\n", "
\n", "
\n", " title4\n", "
\n", "
\n", "
\n", "
\n", " title1\n", "
\n", "\n", "
\n", "
\n", "\n", "
\n", "
\n", "
\n", " \n" ], "text/plain": [ "HTML{String}(\"
\\n
\\n
\\n
\\n y\\n
\\n
\\n 5\\n
\\n\\n
\\n
\\n
\\n t\\n
\\n
\\n
\\n
\\n title1\\n
\\n
\\n title2\\n
\\n
\\n title3\\n
\\n
\\n title4\\n
\\n
\\n
\\n
\\n title1\\n
\\n\\n
\\n
\\n\\n
\\n
\\n
\\n \\n\")" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " var _guiBootup = function (curCallback) {\n", " Jupyter.notebook.kernel.comm_manager.unregister_target(\"interact-789e26cd-502a-4516-b869-f6dcf0f8e6e5\")\n", " Jupyter.notebook.kernel.comm_manager.register_target(\"interact-789e26cd-502a-4516-b869-f6dcf0f8e6e5\", function (comm, msg) {\n", " globalComms[\"interact-789e26cd-502a-4516-b869-f6dcf0f8e6e5\"] = comm;\n", "\n", " comm.on_msg(function(msg) {\n", " if ( \"json\" in msg.content.data ) {\n", " var workPlot = $(\"#js-interact__789e26cd-502a-4516-b869-f6dcf0f8e6e5 .js-plotly-plot\")[0];\n", " if ( typeof workPlot === \"undefined\" ) { alert(\"Could not find plotly plot!\"); }\n", "\n", " var workJson = msg.content.data.json.plot;\n", " customPlotlyReact(workPlot, workJson.data, workJson.layout, workJson.config);\n", "\n", " $(\"#js-interact__789e26cd-502a-4516-b869-f6dcf0f8e6e5 .js-new-plot-script\").replaceWith(msg.content.data.json.script);\n", " } else {\n", " if ( \"html\" in msg.content.data ) {\n", " var tmpDisplay = $(\"#js-interact__789e26cd-502a-4516-b869-f6dcf0f8e6e5 .js-display\");\n", " tmpDisplay.html(msg.content.data.html);\n", " } else {\n", " if ( \"text\" in msg.content.data ) {\n", " console.log(msg.content.data.text);\n", " } else {\n", " alert(\"Unrecognized interact content type!\");\n", " }\n", " }\n", " }\n", " });\n", "\n", " comm.on_close(function(msg) { console.log(\"Julia close message: \" + msg); });\n", " $(\"#js-interact__789e26cd-502a-4516-b869-f6dcf0f8e6e5\").trigger(\"interact\");\n", " })\n", "\n", " var curCommand = 'Main.SimplePlots.interact_comms[\"interact-789e26cd-502a-4516-b869-f6dcf0f8e6e5\"][] += 10';\n", " Jupyter.notebook.kernel.execute(curCommand, {\"iopub\": {\"output\": function(tmpMessage) {\n", " console.log(tmpMessage)\n", " }}});\n", "\n", " if ( typeof curCallback !== \"undefined\" ) { curCallback(); }\n", " }\n", "\n", " if ( typeof Jupyter === \"undefined\" ) {\n", " customPlotLoader(function() {\n", " $(\"#js-interact__789e26cd-502a-4516-b869-f6dcf0f8e6e5\").trigger(\"interact\");\n", " });\n", " } else {\n", " if (Jupyter.notebook.kernel) {\n", " _guiBootup()\n", " } else {\n", " Jupyter.notebook.events.one('kernel_ready.Kernel', (e) => {\n", " _guiBootup(function() {\n", " customPlotLoader(function() {\n", " $(\"#js-interact__789e26cd-502a-4516-b869-f6dcf0f8e6e5\").trigger(\"interact\");\n", " });\n", " });\n", " });\n", " }\n", " }\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " 1.318942 seconds (3.22 M allocations: 154.547 MiB, 3.16% gc time)\n" ] } ], "source": [ "function bar()\n", " yy = rand(10)\n", " xx = slider(2:6, value=5, label=\"y\")\n", " SimplePlots.@gui for x in xx, t = \"title\" .* string.(1:4)\n", " plot(x .* 1:10, yy, title=t)\n", " end\n", "end\n", "\n", "@time bar()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", " y\n", "
\n", "
\n", " 5\n", "
\n", "\n", "
\n", "
\n", "
\n", " t\n", "
\n", "
\n", "
\n", "
\n", " title1\n", "
\n", "
\n", " title2\n", "
\n", "
\n", " title3\n", "
\n", "
\n", " title4\n", "
\n", "
\n", "
\n", "
\n", " title1\n", "
\n", "\n", "
\n", "
\n", "\n", "
\n", "
\n", "
\n", " \n" ], "text/plain": [ "HTML{String}(\"
\\n
\\n
\\n
\\n y\\n
\\n
\\n 5\\n
\\n\\n
\\n
\\n
\\n t\\n
\\n
\\n
\\n
\\n title1\\n
\\n
\\n title2\\n
\\n
\\n title3\\n
\\n
\\n title4\\n
\\n
\\n
\\n
\\n title1\\n
\\n\\n
\\n
\\n\\n
\\n
\\n
\\n \\n\")" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " var _guiBootup = function (curCallback) {\n", " Jupyter.notebook.kernel.comm_manager.unregister_target(\"interact-1f0eb025-9bea-4667-879a-833ef3f7b415\")\n", " Jupyter.notebook.kernel.comm_manager.register_target(\"interact-1f0eb025-9bea-4667-879a-833ef3f7b415\", function (comm, msg) {\n", " globalComms[\"interact-1f0eb025-9bea-4667-879a-833ef3f7b415\"] = comm;\n", "\n", " comm.on_msg(function(msg) {\n", " if ( \"json\" in msg.content.data ) {\n", " var workPlot = $(\"#js-interact__1f0eb025-9bea-4667-879a-833ef3f7b415 .js-plotly-plot\")[0];\n", " if ( typeof workPlot === \"undefined\" ) { alert(\"Could not find plotly plot!\"); }\n", "\n", " var workJson = msg.content.data.json.plot;\n", " customPlotlyReact(workPlot, workJson.data, workJson.layout, workJson.config);\n", "\n", " $(\"#js-interact__1f0eb025-9bea-4667-879a-833ef3f7b415 .js-new-plot-script\").replaceWith(msg.content.data.json.script);\n", " } else {\n", " if ( \"html\" in msg.content.data ) {\n", " var tmpDisplay = $(\"#js-interact__1f0eb025-9bea-4667-879a-833ef3f7b415 .js-display\");\n", " tmpDisplay.html(msg.content.data.html);\n", " } else {\n", " if ( \"text\" in msg.content.data ) {\n", " console.log(msg.content.data.text);\n", " } else {\n", " alert(\"Unrecognized interact content type!\");\n", " }\n", " }\n", " }\n", " });\n", "\n", " comm.on_close(function(msg) { console.log(\"Julia close message: \" + msg); });\n", " $(\"#js-interact__1f0eb025-9bea-4667-879a-833ef3f7b415\").trigger(\"interact\");\n", " })\n", "\n", " var curCommand = 'Main.SimplePlots.interact_comms[\"interact-1f0eb025-9bea-4667-879a-833ef3f7b415\"][] += 10';\n", " Jupyter.notebook.kernel.execute(curCommand, {\"iopub\": {\"output\": function(tmpMessage) {\n", " console.log(tmpMessage)\n", " }}});\n", "\n", " if ( typeof curCallback !== \"undefined\" ) { curCallback(); }\n", " }\n", "\n", " if ( typeof Jupyter === \"undefined\" ) {\n", " customPlotLoader(function() {\n", " $(\"#js-interact__1f0eb025-9bea-4667-879a-833ef3f7b415\").trigger(\"interact\");\n", " });\n", " } else {\n", " if (Jupyter.notebook.kernel) {\n", " _guiBootup()\n", " } else {\n", " Jupyter.notebook.events.one('kernel_ready.Kernel', (e) => {\n", " _guiBootup(function() {\n", " customPlotLoader(function() {\n", " $(\"#js-interact__1f0eb025-9bea-4667-879a-833ef3f7b415\").trigger(\"interact\");\n", " });\n", " });\n", " });\n", " }\n", " }\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " 0.021036 seconds (33.01 k allocations: 1.935 MiB)\n" ] } ], "source": [ "function baz()\n", " yy = rand(10)\n", " xx = slider(2:6, value=5, label=\"y\")\n", " SimplePlots.@manipulate for x in xx, t = \"title\" .* string.(1:4)\n", " plot(x .* 1:10, yy, title=t)\n", " end\n", "end\n", "\n", "@time baz()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", " x\n", "
\n", "
\n", " 2\n", "
\n", "\n", "
\n", "
\n", "
\n", " t\n", "
\n", "
\n", "
\n", "
\n", " title 1\n", "
\n", "
\n", " title 2\n", "
\n", "
\n", "
\n", "
\n", " title 1\n", "
\n", "\n", "
\n", "
\n", "\n", "
\n", "
\n", "
\n", " \n" ], "text/plain": [ "HTML{String}(\"
\\n
\\n
\\n
\\n x\\n
\\n
\\n 2\\n
\\n\\n
\\n
\\n
\\n t\\n
\\n
\\n
\\n
\\n title 1\\n
\\n
\\n title 2\\n
\\n
\\n
\\n
\\n title 1\\n
\\n\\n
\\n
\\n\\n
\\n
\\n
\\n \\n\")" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " var _guiBootup = function (curCallback) {\n", " Jupyter.notebook.kernel.comm_manager.unregister_target(\"interact-e70e0cbd-218d-4253-8f77-830c330cd51d\")\n", " Jupyter.notebook.kernel.comm_manager.register_target(\"interact-e70e0cbd-218d-4253-8f77-830c330cd51d\", function (comm, msg) {\n", " globalComms[\"interact-e70e0cbd-218d-4253-8f77-830c330cd51d\"] = comm;\n", "\n", " comm.on_msg(function(msg) {\n", " if ( \"json\" in msg.content.data ) {\n", " var workPlot = $(\"#js-interact__e70e0cbd-218d-4253-8f77-830c330cd51d .js-plotly-plot\")[0];\n", " if ( typeof workPlot === \"undefined\" ) { alert(\"Could not find plotly plot!\"); }\n", "\n", " var workJson = msg.content.data.json.plot;\n", " customPlotlyReact(workPlot, workJson.data, workJson.layout, workJson.config);\n", "\n", " $(\"#js-interact__e70e0cbd-218d-4253-8f77-830c330cd51d .js-new-plot-script\").replaceWith(msg.content.data.json.script);\n", " } else {\n", " if ( \"html\" in msg.content.data ) {\n", " var tmpDisplay = $(\"#js-interact__e70e0cbd-218d-4253-8f77-830c330cd51d .js-display\");\n", " tmpDisplay.html(msg.content.data.html);\n", " } else {\n", " if ( \"text\" in msg.content.data ) {\n", " console.log(msg.content.data.text);\n", " } else {\n", " alert(\"Unrecognized interact content type!\");\n", " }\n", " }\n", " }\n", " });\n", "\n", " comm.on_close(function(msg) { console.log(\"Julia close message: \" + msg); });\n", " $(\"#js-interact__e70e0cbd-218d-4253-8f77-830c330cd51d\").trigger(\"interact\");\n", " })\n", "\n", " var curCommand = 'Main.SimplePlots.interact_comms[\"interact-e70e0cbd-218d-4253-8f77-830c330cd51d\"][] += 10';\n", " Jupyter.notebook.kernel.execute(curCommand, {\"iopub\": {\"output\": function(tmpMessage) {\n", " console.log(tmpMessage)\n", " }}});\n", "\n", " if ( typeof curCallback !== \"undefined\" ) { curCallback(); }\n", " }\n", "\n", " if ( typeof Jupyter === \"undefined\" ) {\n", " customPlotLoader(function() {\n", " $(\"#js-interact__e70e0cbd-218d-4253-8f77-830c330cd51d\").trigger(\"interact\");\n", " });\n", " } else {\n", " if (Jupyter.notebook.kernel) {\n", " _guiBootup()\n", " } else {\n", " Jupyter.notebook.events.one('kernel_ready.Kernel', (e) => {\n", " _guiBootup(function() {\n", " customPlotLoader(function() {\n", " $(\"#js-interact__e70e0cbd-218d-4253-8f77-830c330cd51d\").trigger(\"interact\");\n", " });\n", " });\n", " });\n", " }\n", " }\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "demoData['interact-e70e0cbd-218d-4253-8f77-830c330cd51d'] = {\"1\":{\"title 1\":{\"config\":{\"responsive\":true},\"data\":[{\"line\":{\"color\":\"#636EFA\"},\"mode\":\"lines\",\"x\":[1,2,3,4,5,6,7,8,9,10],\"y\":[0.7458307132738837,0.32794359954127117,0.984018250421657,0.6716286769898272,0.8734911491278763,0.5942825884347318,0.020617334921175123,0.03503579682216795,0.847022048934158,0.3450448898286045]}],\"layout\":{\"showlegend\":true,\"xaxis\":{\"autorange\":true,\"type\":\"linear\"},\"annotations\":[],\"title\":\"title 1\",\"yaxis\":{\"autorange\":true,\"type\":\"linear\"},\"shapes\":[],\"legend\":{}}},\"title 2\":{\"config\":{\"responsive\":true},\"data\":[{\"line\":{\"color\":\"#636EFA\"},\"mode\":\"lines\",\"x\":[1,2,3,4,5,6,7,8,9,10],\"y\":[0.7458307132738837,0.32794359954127117,0.984018250421657,0.6716286769898272,0.8734911491278763,0.5942825884347318,0.020617334921175123,0.03503579682216795,0.847022048934158,0.3450448898286045]}],\"layout\":{\"showlegend\":true,\"xaxis\":{\"autorange\":true,\"type\":\"linear\"},\"annotations\":[],\"title\":\"title 2\",\"yaxis\":{\"autorange\":true,\"type\":\"linear\"},\"shapes\":[],\"legend\":{}}}},\"2\":{\"title 1\":{\"config\":{\"responsive\":true},\"data\":[{\"line\":{\"color\":\"#636EFA\"},\"mode\":\"lines\",\"x\":[2,3,4,5,6,7,8,9,10],\"y\":[0.7458307132738837,0.32794359954127117,0.984018250421657,0.6716286769898272,0.8734911491278763,0.5942825884347318,0.020617334921175123,0.03503579682216795,0.847022048934158,0.3450448898286045]}],\"layout\":{\"showlegend\":true,\"xaxis\":{\"autorange\":true,\"type\":\"linear\"},\"annotations\":[],\"title\":\"title 1\",\"yaxis\":{\"autorange\":true,\"type\":\"linear\"},\"shapes\":[],\"legend\":{}}},\"title 2\":{\"config\":{\"responsive\":true},\"data\":[{\"line\":{\"color\":\"#636EFA\"},\"mode\":\"lines\",\"x\":[2,3,4,5,6,7,8,9,10],\"y\":[0.7458307132738837,0.32794359954127117,0.984018250421657,0.6716286769898272,0.8734911491278763,0.5942825884347318,0.020617334921175123,0.03503579682216795,0.847022048934158,0.3450448898286045]}],\"layout\":{\"showlegend\":true,\"xaxis\":{\"autorange\":true,\"type\":\"linear\"},\"annotations\":[],\"title\":\"title 2\",\"yaxis\":{\"autorange\":true,\"type\":\"linear\"},\"shapes\":[],\"legend\":{}}}},\"3\":{\"title 1\":{\"config\":{\"responsive\":true},\"data\":[{\"line\":{\"color\":\"#636EFA\"},\"mode\":\"lines\",\"x\":[3,4,5,6,7,8,9,10],\"y\":[0.7458307132738837,0.32794359954127117,0.984018250421657,0.6716286769898272,0.8734911491278763,0.5942825884347318,0.020617334921175123,0.03503579682216795,0.847022048934158,0.3450448898286045]}],\"layout\":{\"showlegend\":true,\"xaxis\":{\"autorange\":true,\"type\":\"linear\"},\"annotations\":[],\"title\":\"title 1\",\"yaxis\":{\"autorange\":true,\"type\":\"linear\"},\"shapes\":[],\"legend\":{}}},\"title 2\":{\"config\":{\"responsive\":true},\"data\":[{\"line\":{\"color\":\"#636EFA\"},\"mode\":\"lines\",\"x\":[3,4,5,6,7,8,9,10],\"y\":[0.7458307132738837,0.32794359954127117,0.984018250421657,0.6716286769898272,0.8734911491278763,0.5942825884347318,0.020617334921175123,0.03503579682216795,0.847022048934158,0.3450448898286045]}],\"layout\":{\"showlegend\":true,\"xaxis\":{\"autorange\":true,\"type\":\"linear\"},\"annotations\":[],\"title\":\"title 2\",\"yaxis\":{\"autorange\":true,\"type\":\"linear\"},\"shapes\":[],\"legend\":{}}}}}\n", " $(\"#js-interact__e70e0cbd-218d-4253-8f77-830c330cd51d\").trigger(\"interact\");\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " 1.804 seconds\n" ] } ], "source": [ "using Dates\n", "init_time = Dates.now()\n", "\n", "yy = rand(10)\n", "SimplePlots.@demo for x in 1:3, t in [\"title 1\", \"title 2\"]\n", " plot(x .* 1:10, yy, title=t)\n", " sleep(1/3)\n", "end\n", "\n", "run_time = ( ( Dates.now() - init_time ) / ( Millisecond(1) * 1000) ) - 2.0\n", "println(\" $(round(run_time,digits=8)) seconds\")" ] } ], "metadata": { "@webio": { "lastCommId": null, "lastKernelId": null }, "kernelspec": { "display_name": "Julia 1.4.0", "language": "julia", "name": "julia-1.4" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.4.0" } }, "nbformat": 4, "nbformat_minor": 4 }