Benchmark: Improve RNA performance tests flexibility.
Make registered py-defined property tests more flexible, by allowing to pass the property type as an argument. And add basic such tests for Bool and String types.
This commit is contained in:
@@ -69,16 +69,26 @@ def _run_runtime_group_register_access(args):
|
||||
do_register = args.get("do_register", False)
|
||||
do_access = args.get("do_access", False)
|
||||
do_get_set = args.get("do_get_set", False)
|
||||
property_type = args.get("property_type", 'IntProperty')
|
||||
property_definition_cb = getattr(bpy.props, property_type)
|
||||
|
||||
# Define basic 'transform' callbacks to test setting value,
|
||||
# default to just setting untransformed value for 'unknown'/undefined property types.
|
||||
property_transform_cb = {
|
||||
'BoolProperty': lambda v: not v,
|
||||
'IntProperty': lambda v: v + 1,
|
||||
'StringProperty': lambda v: ("B" if (v and v[0] == "A") else "A") + v[1:],
|
||||
}.get(property_type, lambda v: v)
|
||||
|
||||
if do_get_set:
|
||||
class DummyGroup(bpy.types.PropertyGroup):
|
||||
dummy_prop: bpy.props.IntProperty(
|
||||
dummy_prop: property_definition_cb(
|
||||
get=lambda self: self.bl_system_properties_get()["dummy_prop"],
|
||||
set=lambda self, val: self.bl_system_properties_get().set("dummy_prop", val),
|
||||
)
|
||||
else:
|
||||
class DummyGroup(bpy.types.PropertyGroup):
|
||||
dummy_prop: bpy.props.IntProperty()
|
||||
dummy_prop: property_definition_cb()
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
@@ -97,7 +107,8 @@ def _run_runtime_group_register_access(args):
|
||||
bpy.types.Scene.dummy_group = bpy.props.PointerProperty(type=DummyGroup)
|
||||
|
||||
for i in range(iterations):
|
||||
sce.dummy_group.dummy_prop += 1
|
||||
v = sce.dummy_group.dummy_prop
|
||||
sce.dummy_group.dummy_prop = property_transform_cb(v)
|
||||
|
||||
del bpy.types.Scene.dummy_group
|
||||
bpy.utils.unregister_class(DummyGroup)
|
||||
@@ -134,7 +145,12 @@ def generate(env):
|
||||
BPYRNATest("Static RNA Stuct Instance Access", _run_static_subdata_instance_access, 10000 * 1000),
|
||||
BPYRNATest("IDProperty Access", _run_idproperty_access, 10000 * 1000),
|
||||
BPYRNATest("Py-Defined Struct Register", _run_runtime_group_register_access, 100 * 1000, {"do_register": True}),
|
||||
BPYRNATest("Py-Defined Property Access", _run_runtime_group_register_access, 10000 * 1000, {"do_access": True}),
|
||||
BPYRNATest("Py-Defined Property Custom Get/Set Access", _run_runtime_group_register_access, 10 * 1000,
|
||||
{"do_access": True, "do_get_set": True}),
|
||||
BPYRNATest("Py-Defined IntProperty Access", _run_runtime_group_register_access, 10000 * 1000,
|
||||
{"do_access": True, "property_type": 'IntProperty'}),
|
||||
BPYRNATest("Py-Defined IntProperty Custom Get/Set Access", _run_runtime_group_register_access, 10 * 1000,
|
||||
{"do_access": True, "do_get_set": True, "property_type": 'IntProperty'}),
|
||||
BPYRNATest("Py-Defined BoolProperty Custom Get/Set Access", _run_runtime_group_register_access, 10 * 1000,
|
||||
{"do_access": True, "do_get_set": True, "property_type": 'BoolProperty'}),
|
||||
BPYRNATest("Py-Defined StringProperty Custom Get/Set Access", _run_runtime_group_register_access, 10 * 1000,
|
||||
{"do_access": True, "do_get_set": True, "property_type": 'StringProperty'}),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user