{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "798985b6-de4b-4c30-a935-85518daa8f1c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import os\n", "import sys\n", "\n", "parent_dir = os.path.abspath(\"..\")\n", "if parent_dir not in sys.path:\n", " sys.path.append(parent_dir)\n", "from magick_benchmark_utils import benchmark_mvg_save\n", "\n", "from functools import partial\n", "from IPython.display import Image\n", "\n", "import pandas as pd\n", "import numpy as np\n", "\n", "from lets_plot import *\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "id": "2a9a84ae-0a38-491f-8b66-4e42230f83a9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def point_plot(n, sh):\n", " np.random.seed(42)\n", " \n", " x = np.random.uniform(size=n)\n", " y = np.random.uniform(size=n)\n", " v = np.random.normal(size=n)\n", "\n", " return ggplot({'x': x, 'y': y, 'v': v}, aes('x', 'y', fill='x')) \\\n", " + geom_point(shape=sh)\n", "\n", "point_plot(1000, 21)" ] }, { "cell_type": "code", "execution_count": 3, "id": "5a2f385b-707c-4af3-bcf2-5ab38a51f681", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "shape_0@1x\n", "[1/7] n=1000 (0.5551s)\n", "[2/7] n=2000 (0.6485s)\n", "[3/7] n=5000 (1.5172s)\n", "[4/7] n=10000 (2.8956s)\n", "[5/7] n=25000 (5.0997s)\n", "[6/7] n=50000 (9.9952s)\n", "[7/7] n=100000 (26.5828s)\n", "shape_1@1x\n", "[1/7] n=1000 (0.4085s)\n", "[2/7] n=2000 (0.5819s)\n", "[3/7] n=5000 (0.9956s)\n", "[4/7] n=10000 (1.4546s)\n", "[5/7] n=25000 (3.5322s)\n", "[6/7] n=50000 (10.0253s)\n", "[7/7] n=100000 (36.4421s)\n", "shape_2@1x\n", "[1/7] n=1000 (0.5265s)\n", "[2/7] n=2000 (0.7139s)\n", "[3/7] n=5000 (1.5638s)\n", "[4/7] n=10000 (2.7701s)\n", "[5/7] n=25000 (6.4460s)\n", "[6/7] n=50000 (16.1024s)\n", "[7/7] n=100000 (42.6294s)\n", "shape_3@1x\n", "[1/7] n=1000 (0.5160s)\n", "[2/7] n=2000 (0.6906s)\n", "[3/7] n=5000 (2.0493s)\n", "[4/7] n=10000 (3.1461s)\n", "[5/7] n=25000 (7.3321s)\n", "[6/7] n=50000 (51.4738s)\n", "[7/7] n=100000 (TIMEOUT)\n", "shape_15@1x\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Collecting stack traces from native extensions (`--native`) is not supported on your platform.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[1/7] n=1000 (0.3733s)\n", "[2/7] n=2000 (0.5360s)\n", "[3/7] n=5000 (0.9785s)\n", "[4/7] n=10000 (1.5960s)\n", "[5/7] n=25000 (6.2854s)\n", "[6/7] n=50000 (7.5084s)\n", "[7/7] n=100000 (20.0107s)\n", "shape_16@1x\n", "[1/7] n=1000 (0.3467s)\n", "[2/7] n=2000 (0.5834s)\n", "[3/7] n=5000 (0.8964s)\n", "[4/7] n=10000 (1.4442s)\n", "[5/7] n=25000 (3.2539s)\n", "[6/7] n=50000 (6.4224s)\n", "[7/7] n=100000 (14.4841s)\n", "shape_21@1x\n", "[1/7] n=1000 (0.3795s)\n", "[2/7] n=2000 (0.5357s)\n", "[3/7] n=5000 (0.9403s)\n", "[4/7] n=10000 (1.6050s)\n", "[5/7] n=25000 (3.4271s)\n", "[6/7] n=50000 (7.9563s)\n", "[7/7] n=100000 (19.9901s)\n", "shape_22@1x\n", "[1/7] n=1000 (0.4779s)\n", "[2/7] n=2000 (0.8100s)\n", "[3/7] n=5000 (1.3540s)\n", "[4/7] n=10000 (2.2808s)\n", "[5/7] n=25000 (7.5345s)\n", "[6/7] n=50000 (11.2940s)\n", "[7/7] n=100000 (31.3340s)\n", "shape_0@2x\n", "[1/7] n=1000 (0.7377s)\n", "[2/7] n=2000 (1.0841s)\n", "[3/7] n=5000 (2.4023s)\n", "[4/7] n=10000 (11.6967s)\n", "[5/7] n=25000 (TIMEOUT)\n", "[6/7] n=50000 (SKIPPED - previous timeout)\n", "[7/7] n=100000 (SKIPPED - previous timeout)\n", "shape_1@2x\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Collecting stack traces from native extensions (`--native`) is not supported on your platform.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[1/7] n=1000 (0.7073s)\n", "[2/7] n=2000 (1.1934s)\n", "[3/7] n=5000 (1.9777s)\n", "[4/7] n=10000 (3.8977s)\n", "[5/7] n=25000 (29.6918s)\n", "[6/7] n=50000 (TIMEOUT)\n", "[7/7] n=100000 (SKIPPED - previous timeout)\n", "shape_2@2x\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Collecting stack traces from native extensions (`--native`) is not supported on your platform.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[1/7] n=1000 (0.7840s)\n", "[2/7] n=2000 (1.3473s)\n", "[3/7] n=5000 (5.9137s)\n", "[4/7] n=10000 (19.4752s)\n", "[5/7] n=25000 (TIMEOUT)\n", "[6/7] n=50000 (SKIPPED - previous timeout)\n", "[7/7] n=100000 (SKIPPED - previous timeout)\n", "shape_3@2x\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Collecting stack traces from native extensions (`--native`) is not supported on your platform.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[1/7] n=1000 (0.7432s)\n", "[2/7] n=2000 (1.1754s)\n", "[3/7] n=5000 (2.7622s)\n", "[4/7] n=10000 (15.4605s)\n", "[5/7] n=25000 (TIMEOUT)\n", "[6/7] n=50000 (SKIPPED - previous timeout)\n", "[7/7] n=100000 (SKIPPED - previous timeout)\n", "shape_15@2x\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Collecting stack traces from native extensions (`--native`) is not supported on your platform.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[1/7] n=1000 (0.6134s)\n", "[2/7] n=2000 (0.7676s)\n", "[3/7] n=5000 (1.3246s)\n", "[4/7] n=10000 (2.2712s)\n", "[5/7] n=25000 (7.4077s)\n", "[6/7] n=50000 (11.3809s)\n", "[7/7] n=100000 (28.3815s)\n", "shape_16@2x\n", "[1/7] n=1000 (0.6138s)\n", "[2/7] n=2000 (0.6421s)\n", "[3/7] n=5000 (1.2220s)\n", "[4/7] n=10000 (1.9385s)\n", "[5/7] n=25000 (4.1532s)\n", "[6/7] n=50000 (12.2579s)\n", "[7/7] n=100000 (19.9301s)\n", "shape_21@2x\n", "[1/7] n=1000 (0.6660s)\n", "[2/7] n=2000 (0.9494s)\n", "[3/7] n=5000 (1.7125s)\n", "[4/7] n=10000 (4.2022s)\n", "[5/7] n=25000 (28.6361s)\n", "[6/7] n=50000 (TIMEOUT)\n", "[7/7] n=100000 (SKIPPED - previous timeout)\n", "shape_22@2x\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Collecting stack traces from native extensions (`--native`) is not supported on your platform.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[1/7] n=1000 (0.7322s)\n", "[2/7] n=2000 (1.0641s)\n", "[3/7] n=5000 (2.6759s)\n", "[4/7] n=10000 (12.7704s)\n", "[5/7] n=25000 (TIMEOUT)\n", "[6/7] n=50000 (SKIPPED - previous timeout)\n", "[7/7] n=100000 (SKIPPED - previous timeout)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Collecting stack traces from native extensions (`--native`) is not supported on your platform.\n" ] } ], "source": [ "ns = [1_000, 2_000, 5_000, 10_000, 25_000, 50_000, 100_000]\n", "shapes = [\n", " 0, 1, 2, 3, # only lines\n", " 15, 16, # only fill\n", " 21, 22 # fill and stroke\n", "]\n", "\n", "dfs = []\n", "\n", "for shape in shapes:\n", " raw_data = benchmark_mvg_save(ns, partial(point_plot, sh=shape), file_prefix=\"shape_\" + str(shape), scale=1, timeout=60)\n", "\n", " df_batch = pd.DataFrame(raw_data).assign(\n", " shape_id=shape,\n", " experiment_group=\"shape_\" + str(shape),\n", " timestamp=pd.Timestamp.now()\n", " )\n", " \n", " dfs.append(df_batch)\n", "\n", "\n", "for shape in shapes:\n", " raw_data = benchmark_mvg_save(ns, partial(point_plot, sh=shape), file_prefix=\"shape_\" + str(shape), scale=2, timeout=60)\n", "\n", " df_batch = pd.DataFrame(raw_data).assign(\n", " shape_id=shape,\n", " experiment_group=\"shape_\" + str(shape),\n", " timestamp=pd.Timestamp.now()\n", " )\n", " \n", " dfs.append(df_batch)\n", "\n", "# Concatenate all at once\n", "df = pd.concat(dfs, ignore_index=True)" ] }, { "cell_type": "code", "execution_count": 4, "id": "a594f912-468c-4f18-a55c-42e85aa66e38", "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", "
nprefixscaletime_maptime_painttime_snapshottime_totalshape_idexperiment_grouptimestamperror
01000shape_010.2928630.0088580.2534200.5551400shape_02025-11-21 16:39:25.198629NaN
12000shape_010.3998550.0156670.2330240.6485460shape_02025-11-21 16:39:25.198629NaN
25000shape_010.7895290.0465030.6812011.5172330shape_02025-11-21 16:39:25.198629NaN
310000shape_012.0429790.0782130.7744392.8956310shape_02025-11-21 16:39:25.198629NaN
425000shape_013.2759480.3293661.4944095.0997230shape_02025-11-21 16:39:25.198629NaN
\n", "
" ], "text/plain": [ " n prefix scale time_map time_paint time_snapshot time_total \\\n", "0 1000 shape_0 1 0.292863 0.008858 0.253420 0.555140 \n", "1 2000 shape_0 1 0.399855 0.015667 0.233024 0.648546 \n", "2 5000 shape_0 1 0.789529 0.046503 0.681201 1.517233 \n", "3 10000 shape_0 1 2.042979 0.078213 0.774439 2.895631 \n", "4 25000 shape_0 1 3.275948 0.329366 1.494409 5.099723 \n", "\n", " shape_id experiment_group timestamp error \n", "0 0 shape_0 2025-11-21 16:39:25.198629 NaN \n", "1 0 shape_0 2025-11-21 16:39:25.198629 NaN \n", "2 0 shape_0 2025-11-21 16:39:25.198629 NaN \n", "3 0 shape_0 2025-11-21 16:39:25.198629 NaN \n", "4 0 shape_0 2025-11-21 16:39:25.198629 NaN " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.head()" ] }, { "cell_type": "code", "execution_count": 5, "id": "1bce66f9-822d-4b22-864f-44011aaea309", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df) + geom_line(aes(x='n', y='time_snapshot', color=as_discrete('shape_id'))) + facet_grid(x='scale')" ] }, { "cell_type": "code", "execution_count": 6, "id": "4a3776ef-f5c0-4413-9878-65a77ad3c2ab", "metadata": {}, "outputs": [], "source": [ "df.to_csv(\"point_variant_optimized.csv\", index=False)" ] }, { "cell_type": "code", "execution_count": null, "id": "8b464854-4e02-4cc8-a225-c66a140526a5", "metadata": {}, "outputs": [], "source": [] } ], "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.12.2" } }, "nbformat": 4, "nbformat_minor": 5 }