{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Benchmark data processing\n", "\n", "Contains the code required to plot the figures in the docs.\n", "\n", "* Build the benchmarks with CMake, using the `BOOST_MYSQL_BENCH` CMake option and the `boost_mysql_bench` CMake target.\n", "* Run the benchmarks with `tools/ci/run_benchmarks.py`, which leaves a .txt file with the results in the current directory.\n", "* Run this notebook to generate the graphs.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from matplotlib import pyplot as plt\n", "\n", "df = pd.read_csv('../private/benchmark-results.txt', header=None) # Update file path as required\n", "df = df.set_index(df.index.map(lambda x: x % df.groupby(0).size()[0]))\n", "df = df.pivot(columns=[0], values=[1])\n", "df.columns = df.columns.get_level_values(0)\n", "df" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def plot_result(df: pd.DataFrame, bench: str, title: str, ax):\n", " cols = [f'{bench}_boost', f'{bench}_libmysqlclient', f'{bench}_libmariadb']\n", " df = df[cols].rename(columns={\n", " f'{bench}_boost': 'Boost.MySQL',\n", " f'{bench}_libmysqlclient': 'libmysqlclient',\n", " f'{bench}_libmariadb': 'libmariadb'\n", " })\n", " mean_val = round(df.mean().mean())\n", " df.plot.box(ylim=(mean_val-150, mean_val+150), ax=ax, title=title, ylabel='Time (ms)')\n", "\n", "\n", "fig, _ = plt.subplots(2, 2, figsize=(15, 15))\n", "\n", "plot_result(df, bench='one_small_row', title='Reading one small row', ax=fig.axes[0])\n", "plot_result(df, bench='one_big_row', title='Reading one big row', ax=fig.axes[1])\n", "plot_result(df, bench='many_rows', title='Reading 5k rows', ax=fig.axes[2])\n", "plot_result(df, bench='stmt_params', title='Statement with params', ax=fig.axes[3])\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "base", "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.8.3" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }