Performance testing of serialization
This test checks the performance improvement of scene setup with serialization feature.
[1]:
import lmenv
env = lmenv.load('.lmenv')
[2]:
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 lmscene
import lightmetrica as lm
[3]:
%load_ext lightmetrica_jupyter
[4]:
lm.init()
lm.log.init('jupyter')
lm.progress.init('jupyter')
lm.info()
[I|0.000] Lightmetrica -- Version 3.0.0 (rev. 70601db) Linux x64
[5]:
scene_names = lmscene.scenes_small()
[6]:
scene_setup_time_df = pd.DataFrame(
columns=['scene loading', 'serialization', 'deserialization'],
index=scene_names)
for scene_name in scene_names:
lm.reset()
lm.load_film('film_output', 'bitmap', {
'w': 1920,
'h': 1080
})
# Load the scene without serialization
def load_scene():
accel = lm.load_accel('accel', 'sahbvh', {})
scene = lm.load_scene('scene', 'default', {
'accel': accel.loc()
})
lmscene.load(scene, env.scene_path, scene_name)
loading_time_without_serialization = timeit.timeit(stmt=load_scene, number=1)
scene_setup_time_df['scene loading'][scene_name] = loading_time_without_serialization
# Export the internal state to a file
def serialize_scene():
lm.save_state_to_file('lm.serialized')
serialization_time = timeit.timeit(stmt=serialize_scene, number=1)
scene_setup_time_df['serialization'][scene_name] = serialization_time
# Import the internal state from the serialized file
lm.reset()
def deserialize_scene():
lm.load_state_from_file('lm.serialized')
deserialization_time = timeit.timeit(stmt=deserialize_scene, number=1)
scene_setup_time_df['deserialization'][scene_name] = deserialization_time
[I|0.018] Loading asset [name='film_output']
[I|0.096] Loading asset [name='accel']
[I|0.096] Loading asset [name='scene']
[I|0.096] Loading asset [name='camera_main']
[I|0.096] Loading asset [name='model_obj']
[I|0.096] .. Loading OBJ file [path='fireplace_room.obj']
[I|0.096] .. Loading MTL file [path='fireplace_room.mtl']
[I|0.422] .. Loading texture [path='wood.ppm']
[I|0.512] .. Loading texture [path='leaf.ppm']
[I|0.514] .. Loading texture [path='picture8.ppm']
[I|0.546] .. Loading texture [path='wood5.ppm']
[I|1.572] Loading asset [name='film_output']
[I|1.651] Loading asset [name='accel']
[I|1.651] Loading asset [name='scene']
[I|1.651] Loading asset [name='camera_main']
[I|1.651] Loading asset [name='model_obj']
[I|1.651] .. Loading OBJ file [path='CornellBox-Sphere.obj']
[I|1.651] .. Loading MTL file [path='CornellBox-Sphere.mtl']
[I|2.189] Loading asset [name='film_output']
[I|2.266] Loading asset [name='accel']
[I|2.267] Loading asset [name='scene']
[I|2.267] Loading asset [name='camera_main']
[I|2.267] Loading asset [name='model_obj']
[I|2.267] .. Loading OBJ file [path='cube.obj']
[I|2.267] .. Loading MTL file [path='default.mtl']
[I|2.267] .. Loading texture [path='default.png']
[7]:
scene_setup_time_df
[7]:
scene loading | serialization | deserialization | |
---|---|---|---|
fireplace_room | 0.502106 | 0.605808 | 0.358062 |
cornell_box_sphere | 0.00285 | 0.292031 | 0.238252 |
cube | 0.011338 | 0.289647 | 0.237782 |