{ "cells": [ { "cell_type": "markdown", "id": "9cd3261f", "metadata": {}, "source": [ "## Performance testing of serialization\n", "\n", "This test checks the performance improvement of scene setup with serialization feature." ] }, { "cell_type": "code", "execution_count": 1, "id": "ee2ef520", "metadata": { "execution": { "iopub.execute_input": "2021-10-22T11:45:24.646038Z", "iopub.status.busy": "2021-10-22T11:45:24.645378Z", "iopub.status.idle": "2021-10-22T11:45:24.740266Z", "shell.execute_reply": "2021-10-22T11:45:24.741130Z" } }, "outputs": [], "source": [ "import lmenv\n", "env = lmenv.load('.lmenv')" ] }, { "cell_type": "code", "execution_count": 2, "id": "2de699c0", "metadata": { "execution": { "iopub.execute_input": "2021-10-22T11:45:24.744932Z", "iopub.status.busy": "2021-10-22T11:45:24.743858Z", "iopub.status.idle": "2021-10-22T11:45:25.266207Z", "shell.execute_reply": "2021-10-22T11:45:25.265765Z" } }, "outputs": [], "source": [ "import os\n", "import imageio\n", "import pandas as pd\n", "import numpy as np\n", "import timeit\n", "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "from mpl_toolkits.axes_grid1 import make_axes_locatable\n", "import lmscene\n", "import lightmetrica as lm" ] }, { "cell_type": "code", "execution_count": 3, "id": "7bea8e47", "metadata": { "execution": { "iopub.execute_input": "2021-10-22T11:45:25.271406Z", "iopub.status.busy": "2021-10-22T11:45:25.270268Z", "iopub.status.idle": "2021-10-22T11:45:25.277299Z", "shell.execute_reply": "2021-10-22T11:45:25.276408Z" } }, "outputs": [], "source": [ "%load_ext lightmetrica_jupyter" ] }, { "cell_type": "code", "execution_count": 4, "id": "528687ec", "metadata": { "execution": { "iopub.execute_input": "2021-10-22T11:45:25.282024Z", "iopub.status.busy": "2021-10-22T11:45:25.281494Z", "iopub.status.idle": "2021-10-22T11:45:25.284081Z", "shell.execute_reply": "2021-10-22T11:45:25.284474Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[I|0.000] Lightmetrica -- Version 3.0.0 (rev. 70601db) Linux x64\n" ] } ], "source": [ "lm.init()\n", "lm.log.init('jupyter')\n", "lm.progress.init('jupyter')\n", "lm.info()" ] }, { "cell_type": "code", "execution_count": 5, "id": "a73fab98", "metadata": { "execution": { "iopub.execute_input": "2021-10-22T11:45:25.287461Z", "iopub.status.busy": "2021-10-22T11:45:25.286776Z", "iopub.status.idle": "2021-10-22T11:45:25.290465Z", "shell.execute_reply": "2021-10-22T11:45:25.290067Z" } }, "outputs": [], "source": [ "scene_names = lmscene.scenes_small()" ] }, { "cell_type": "code", "execution_count": 6, "id": "41bd7493", "metadata": { "execution": { "iopub.execute_input": "2021-10-22T11:45:26.853486Z", "iopub.status.busy": "2021-10-22T11:45:25.702841Z", "iopub.status.idle": "2021-10-22T11:45:28.092898Z", "shell.execute_reply": "2021-10-22T11:45:28.093277Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[I|0.018] Loading asset [name='film_output']\n", "[I|0.096] Loading asset [name='accel']\n", "[I|0.096] Loading asset [name='scene']\n", "[I|0.096] Loading asset [name='camera_main']\n", "[I|0.096] Loading asset [name='model_obj']\n", "[I|0.096] .. Loading OBJ file [path='fireplace_room.obj']\n", "[I|0.096] .. Loading MTL file [path='fireplace_room.mtl']\n", "[I|0.422] .. Loading texture [path='wood.ppm']\n", "[I|0.512] .. Loading texture [path='leaf.ppm']\n", "[I|0.514] .. Loading texture [path='picture8.ppm']\n", "[I|0.546] .. Loading texture [path='wood5.ppm']\n", "[I|1.572] Loading asset [name='film_output']\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[I|1.651] Loading asset [name='accel']\n", "[I|1.651] Loading asset [name='scene']\n", "[I|1.651] Loading asset [name='camera_main']\n", "[I|1.651] Loading asset [name='model_obj']\n", "[I|1.651] .. Loading OBJ file [path='CornellBox-Sphere.obj']\n", "[I|1.651] .. Loading MTL file [path='CornellBox-Sphere.mtl']\n", "[I|2.189] Loading asset [name='film_output']\n", "[I|2.266] Loading asset [name='accel']\n", "[I|2.267] Loading asset [name='scene']\n", "[I|2.267] Loading asset [name='camera_main']\n", "[I|2.267] Loading asset [name='model_obj']\n", "[I|2.267] .. Loading OBJ file [path='cube.obj']\n", "[I|2.267] .. Loading MTL file [path='default.mtl']\n", "[I|2.267] .. Loading texture [path='default.png']\n" ] } ], "source": [ "scene_setup_time_df = pd.DataFrame(\n", " columns=['scene loading', 'serialization', 'deserialization'],\n", " index=scene_names)\n", "for scene_name in scene_names:\n", " lm.reset()\n", " \n", " lm.load_film('film_output', 'bitmap', {\n", " 'w': 1920,\n", " 'h': 1080\n", " })\n", " \n", " # Load the scene without serialization\n", " def load_scene():\n", " accel = lm.load_accel('accel', 'sahbvh', {})\n", " scene = lm.load_scene('scene', 'default', {\n", " 'accel': accel.loc()\n", " })\n", " lmscene.load(scene, env.scene_path, scene_name)\n", " loading_time_without_serialization = timeit.timeit(stmt=load_scene, number=1)\n", " scene_setup_time_df['scene loading'][scene_name] = loading_time_without_serialization\n", " \n", " # Export the internal state to a file\n", " def serialize_scene():\n", " lm.save_state_to_file('lm.serialized')\n", " serialization_time = timeit.timeit(stmt=serialize_scene, number=1)\n", " scene_setup_time_df['serialization'][scene_name] = serialization_time\n", " \n", " # Import the internal state from the serialized file\n", " lm.reset()\n", " def deserialize_scene():\n", " lm.load_state_from_file('lm.serialized')\n", " deserialization_time = timeit.timeit(stmt=deserialize_scene, number=1)\n", " scene_setup_time_df['deserialization'][scene_name] = deserialization_time" ] }, { "cell_type": "code", "execution_count": 7, "id": "2f4129f2", "metadata": { "execution": { "iopub.execute_input": "2021-10-22T11:45:28.103855Z", "iopub.status.busy": "2021-10-22T11:45:28.101328Z", "iopub.status.idle": "2021-10-22T11:45:28.108639Z", "shell.execute_reply": "2021-10-22T11:45:28.109025Z" } }, "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", "
scene loadingserializationdeserialization
fireplace_room0.5021060.6058080.358062
cornell_box_sphere0.002850.2920310.238252
cube0.0113380.2896470.237782
\n", "
" ], "text/plain": [ " scene loading serialization deserialization\n", "fireplace_room 0.502106 0.605808 0.358062\n", "cornell_box_sphere 0.00285 0.292031 0.238252\n", "cube 0.011338 0.289647 0.237782" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scene_setup_time_df" ] } ], "metadata": { "jupytext": { "formats": "ipynb,py:light", "text_representation": { "extension": ".py", "format_name": "light", "format_version": "1.4", "jupytext_version": "1.2.4" } }, "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.7.10" } }, "nbformat": 4, "nbformat_minor": 5 }