{ "cells": [ { "cell_type": "markdown", "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, "metadata": {}, "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 lmfunctest as ft\n", "import lmscene\n", "import lightmetrica as lm" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "%load_ext lightmetrica_jupyter" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[I|0.000|114@user ] Lightmetrica -- Version 3.0.0 (rev. fe30e7c) Linux x64\n" ] } ], "source": [ "lm.init('user::default', {})\n", "lm.parallel.init('parallel::openmp', {\n", " 'numThreads': -1\n", "})\n", "lm.log.init('logger::jupyter', {})\n", "lm.info()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "scenes = lmscene.scenes_small()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[I|0.026|48@assets ] Loading asset [name='film_output']\n", "[I|0.112|48@assets ] Loading asset [name='camera_main']\n", "[I|0.112|48@assets ] Loading asset [name='model_obj']\n", "[I|0.113|29@objload] Loading OBJ file [path='fireplace_room.obj']\n", "[I|0.113|169@objloa] Loading MTL file [path='fireplace_room.mtl']\n", "[I|0.113|44@texture] Loading texture [path='wood.ppm']\n", "[I|0.219|44@texture] Loading texture [path='leaf.ppm']\n", "[I|0.222|44@texture] Loading texture [path='picture8.ppm']\n", "[I|0.264|44@texture] Loading texture [path='wood5.ppm']\n", "[I|0.702|246@scene ] Building acceleration structure [name='accel::sahbvh']\n", "[I|0.704|131@accel_] Flattening scene\n", "[I|0.733|261@accel_] Building\n", "[I|1.486|179@user ] Saving state to stream\n", "[I|3.094|186@user ] Loading state from stream\n", "[I|3.759|48@assets ] Loading asset [name='film_output']\n", "[I|3.849|48@assets ] Loading asset [name='camera_main']\n", "[I|3.849|48@assets ] Loading asset [name='model_obj']\n", "[I|3.849|29@objload] Loading OBJ file [path='CornellBox-Sphere.obj']\n", "[I|3.849|169@objloa] Loading MTL file [path='CornellBox-Sphere.mtl']\n", "[I|3.852|246@scene ] Building acceleration structure [name='accel::sahbvh']\n", "[I|3.852|131@accel_] Flattening scene\n", "[I|3.852|261@accel_] Building\n", "[I|3.880|179@user ] Saving state to stream\n", "[I|4.316|186@user ] Loading state from stream\n", "[I|4.618|48@assets ] Loading asset [name='film_output']\n", "[I|4.707|48@assets ] Loading asset [name='camera_main']\n", "[I|4.707|48@assets ] Loading asset [name='model_obj']\n", "[I|4.707|29@objload] Loading OBJ file [path='cube.obj']\n", "[I|4.707|169@objloa] Loading MTL file [path='default.mtl']\n", "[I|4.707|44@texture] Loading texture [path='default.png']\n", "[I|4.723|246@scene ] Building acceleration structure [name='accel::sahbvh']\n", "[I|4.723|131@accel_] Flattening scene\n", "[I|4.723|261@accel_] Building\n", "[I|4.731|179@user ] Saving state to stream\n", "[I|5.164|186@user ] Loading state from stream\n" ] } ], "source": [ "scene_setup_time_df = pd.DataFrame(\n", " columns=['scene loading', 'serialization', 'deserialization'],\n", " index=scenes)\n", "for scene in scenes:\n", " lm.reset()\n", " \n", " lm.asset('film_output', 'film::bitmap', {\n", " 'w': 1920,\n", " 'h': 1080\n", " })\n", " \n", " # Load the scene without serialization\n", " def load_scene():\n", " lmscene.load(ft.env.scene_path, scene)\n", " lm.build('accel::sahbvh', {})\n", " loading_time_without_serialization = timeit.timeit(stmt=load_scene, number=1)\n", " scene_setup_time_df['scene loading'][scene] = loading_time_without_serialization\n", " \n", " # Export the internal state to a file\n", " def serialize_scene():\n", " lm.serialize('lm.serialized')\n", " serialization_time = timeit.timeit(stmt=serialize_scene, number=1)\n", " scene_setup_time_df['serialization'][scene] = serialization_time\n", " \n", " # Import the internal state from the serialized file\n", " lm.reset()\n", " def deserialize_scene():\n", " lm.deserialize('lm.serialized')\n", " deserialization_time = timeit.timeit(stmt=deserialize_scene, number=1)\n", " scene_setup_time_df['deserialization'][scene] = deserialization_time" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | scene loading | \n", "serialization | \n", "deserialization | \n", "
|---|---|---|---|
| fireplace_room | \n", "1.36476 | \n", "1.61388 | \n", "0.662624 | \n", "
| cornell_box_sphere | \n", "0.00919913 | \n", "0.45589 | \n", "0.30194 | \n", "
| cube | \n", "0.0163787 | \n", "0.439204 | \n", "0.299878 | \n", "