import os
import sys
parent_dir = os.path.abspath("..")
if parent_dir not in sys.path:
sys.path.append(parent_dir)
from magick_benchmark_utils import benchmark_mvg_save
from functools import partial
from IPython.display import Image
import pandas as pd
import numpy as np
from lets_plot import *
LetsPlot.setup_html()
def point_plot(n, sh):
np.random.seed(42)
x = np.random.uniform(size=n)
y = np.random.uniform(size=n)
v = np.random.normal(size=n)
return ggplot({'x': x, 'y': y, 'v': v}, aes('x', 'y', fill='x')) \
+ geom_point(shape=sh)
point_plot(1000, 21)
ns = [1_000, 2_000, 5_000, 10_000, 25_000, 50_000, 100_000]
shapes = [
0, 1, 2, 3, # only lines
15, 16, # only fill
21, 22 # fill and stroke
]
dfs = []
for shape in shapes:
raw_data = benchmark_mvg_save(ns, partial(point_plot, sh=shape), file_prefix="shape_" + str(shape), scale=1, timeout=60)
df_batch = pd.DataFrame(raw_data).assign(
shape_id=shape,
experiment_group="shape_" + str(shape),
timestamp=pd.Timestamp.now()
)
dfs.append(df_batch)
for shape in shapes:
raw_data = benchmark_mvg_save(ns, partial(point_plot, sh=shape), file_prefix="shape_" + str(shape), scale=2, timeout=60)
df_batch = pd.DataFrame(raw_data).assign(
shape_id=shape,
experiment_group="shape_" + str(shape),
timestamp=pd.Timestamp.now()
)
dfs.append(df_batch)
# Concatenate all at once
df = pd.concat(dfs, ignore_index=True)
df.head()
ggplot(df) + geom_line(aes(x='n', y='time_snapshot', color=as_discrete('shape_id'))) + facet_grid(x='scale')
df.to_csv("point_variant_optimized.csv", index=False)