Performance testing of serializationΒΆ

This test checks the performance improvement of scene setup with serialization feature.

[1]:
import os
import imageio
import pandas as pd
import numpy as np
import timeit
%matplotlib inline
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import lmfunctest as ft
import lmscene
import lightmetrica as lm
[2]:
%load_ext lightmetrica_jupyter
[3]:
lm.init('user::default', {})
lm.parallel.init('parallel::openmp', {
    'numThreads': -1
})
lm.log.init('logger::jupyter', {})
lm.info()
[I|0.000|114@user  ] Lightmetrica -- Version 3.0.0 (rev. fe30e7c) Linux x64
[4]:
scenes = lmscene.scenes_small()
[5]:
scene_setup_time_df = pd.DataFrame(
    columns=['scene loading', 'serialization', 'deserialization'],
    index=scenes)
for scene in scenes:
    lm.reset()

    lm.asset('film_output', 'film::bitmap', {
        'w': 1920,
        'h': 1080
    })

    # Load the scene without serialization
    def load_scene():
        lmscene.load(ft.env.scene_path, scene)
        lm.build('accel::sahbvh', {})
    loading_time_without_serialization = timeit.timeit(stmt=load_scene, number=1)
    scene_setup_time_df['scene loading'][scene] = loading_time_without_serialization

    # Export the internal state to a file
    def serialize_scene():
        lm.serialize('lm.serialized')
    serialization_time = timeit.timeit(stmt=serialize_scene, number=1)
    scene_setup_time_df['serialization'][scene] = serialization_time

    # Import the internal state from the serialized file
    lm.reset()
    def deserialize_scene():
        lm.deserialize('lm.serialized')
    deserialization_time = timeit.timeit(stmt=deserialize_scene, number=1)
    scene_setup_time_df['deserialization'][scene] = deserialization_time
[I|0.026|48@assets ] Loading asset [name='film_output']
[I|0.112|48@assets ] Loading asset [name='camera_main']
[I|0.112|48@assets ] Loading asset [name='model_obj']
[I|0.113|29@objload]   Loading OBJ file [path='fireplace_room.obj']
[I|0.113|169@objloa]   Loading MTL file [path='fireplace_room.mtl']
[I|0.113|44@texture]   Loading texture [path='wood.ppm']
[I|0.219|44@texture]   Loading texture [path='leaf.ppm']
[I|0.222|44@texture]   Loading texture [path='picture8.ppm']
[I|0.264|44@texture]   Loading texture [path='wood5.ppm']
[I|0.702|246@scene ] Building acceleration structure [name='accel::sahbvh']
[I|0.704|131@accel_]   Flattening scene
[I|0.733|261@accel_]   Building
[I|1.486|179@user  ] Saving state to stream
[I|3.094|186@user  ] Loading state from stream
[I|3.759|48@assets ] Loading asset [name='film_output']
[I|3.849|48@assets ] Loading asset [name='camera_main']
[I|3.849|48@assets ] Loading asset [name='model_obj']
[I|3.849|29@objload]   Loading OBJ file [path='CornellBox-Sphere.obj']
[I|3.849|169@objloa]   Loading MTL file [path='CornellBox-Sphere.mtl']
[I|3.852|246@scene ] Building acceleration structure [name='accel::sahbvh']
[I|3.852|131@accel_]   Flattening scene
[I|3.852|261@accel_]   Building
[I|3.880|179@user  ] Saving state to stream
[I|4.316|186@user  ] Loading state from stream
[I|4.618|48@assets ] Loading asset [name='film_output']
[I|4.707|48@assets ] Loading asset [name='camera_main']
[I|4.707|48@assets ] Loading asset [name='model_obj']
[I|4.707|29@objload]   Loading OBJ file [path='cube.obj']
[I|4.707|169@objloa]   Loading MTL file [path='default.mtl']
[I|4.707|44@texture]   Loading texture [path='default.png']
[I|4.723|246@scene ] Building acceleration structure [name='accel::sahbvh']
[I|4.723|131@accel_]   Flattening scene
[I|4.723|261@accel_]   Building
[I|4.731|179@user  ] Saving state to stream
[I|5.164|186@user  ] Loading state from stream
[6]:
scene_setup_time_df
[6]:
scene loading serialization deserialization
fireplace_room 1.36476 1.61388 0.662624
cornell_box_sphere 0.00919913 0.45589 0.30194
cube 0.0163787 0.439204 0.299878