11from __future__ import annotations
22
3+ import numpy as np
34import functools
45import pathlib
56import time
2930
3031import SkinPlusPlusPymxs
3132
32- skin_data = SkinPlusPlusPymxs .SkinData ()
33- skin_data .initialise ("Sphere001" )
34- skin_weights = skin_data .getSkinWeights ()
35- print (skin_weights [0 ][1 ])
33+ # skin_data = SkinPlusPlusPymxs.SkinData()
34+ # skin_data.initialise("Sphere001")
35+ # skin_weights = skin_data.getSkinWeights()
36+ # print(skin_weights[0][1])
3637
3738
3839__loops__ = 1
@@ -45,7 +46,7 @@ def get_loops():
4546 return __loops__
4647
4748
48- def timer (data_dict : dict [str , tuple [float , Any ]]) -> Callable :
49+ def timer (data_dict : dict [str , tuple [float , Any , str ]]) -> Callable :
4950 def wrapper (function : Callable ) -> Callable :
5051 @functools .wraps (function )
5152 def wrapper_timer (* args , ** kwargs ) -> Any :
@@ -54,7 +55,7 @@ def wrapper_timer(*args, **kwargs) -> Any:
5455 for _ in range (get_loops ()):
5556 value = function (* args , ** kwargs )
5657 run_time = time .perf_counter () - start_time
57- data_dict [f"{ function .__name__ !r} " ] = (run_time , value )
58+ data_dict [f"{ function .__name__ !r} " ] = (run_time , value , function . __name__ )
5859 return value
5960 return wrapper_timer
6061 return wrapper
@@ -91,7 +92,7 @@ def SetSkinWeights(node, boneIDs, weights) -> None:
9192 ReplaceVertexWeights (skinModifier , vertexIndex , boneIDs [vertexIndex ], weights [vertexIndex ])
9293
9394
94- get_timer_dict : dict [str , tuple [float , Any ]] = {}
95+ get_timer_dict : dict [str , tuple [float , Any , str ]] = {}
9596@timer (get_timer_dict )
9697def mxs_GetSkinWeights (_obj ):
9798 data = mxsGetSkinWeights (_obj )
@@ -100,6 +101,15 @@ def mxs_GetSkinWeights(_obj):
100101
101102 return weights , boneIDs
102103
104+ @timer (get_timer_dict )
105+ def mxs_GetSkinWeights_NP (_obj ):
106+ data = mxsGetSkinWeights (_obj )
107+
108+ weights = np .array ([np .array (list (weights ), dtype = float ) for weights in data [0 ]], dtype = float )
109+ boneIDs = np .array ([np .array (list (boneIDs ), dtype = float ) for boneIDs in data [1 ]], dtype = float )
110+ # boneIDs = [list(boneIDs) for boneIDs in data[1]]
111+
112+ return weights , boneIDs
103113
104114@timer (get_timer_dict )
105115def pymxs_GetSkinWeights (_obj ):
@@ -132,26 +142,37 @@ def cpppf_GetSkinWeights(_obj):
132142
133143@timer (get_timer_dict )
134144def pybind11_GetSkinWeights (_obj ):
135-
136- return SkinPlusPlusPymxs .get_skin_weights (_obj .Name )
145+ return SkinPlusPlusPymxs .get_skin_weights (_obj .Name , 0 )
137146
138147@timer (get_timer_dict )
139- def pybind11np_GetSkinWeights (_obj ):
148+ def pybind11_GetSkinWeights_take_ownership (_obj ):
149+ return SkinPlusPlusPymxs .get_skin_weights (_obj .Name , 1 )
140150
141- return SkinPlusPlusPymxs .get_skin_weights_np (_obj .Name )
151+ @timer (get_timer_dict )
152+ def pybind11_GetSkinWeights_copy (_obj ):
153+ return SkinPlusPlusPymxs .get_skin_weights (_obj .Name , 2 )
142154
143155@timer (get_timer_dict )
144- def pybind11npmove_GetSkinWeights (_obj ):
156+ def pybind11_GetSkinWeights_move (_obj ):
157+ return SkinPlusPlusPymxs .get_skin_weights (_obj .Name , 3 )
145158
146- return SkinPlusPlusPymxs .get_skin_weights_np_move (_obj .Name )
159+ @timer (get_timer_dict )
160+ def pybind11_GetSkinWeights_reference (_obj ):
161+ return SkinPlusPlusPymxs .get_skin_weights (_obj .Name , 4 )
147162
148163@timer (get_timer_dict )
149- def pybind11nptakeownership_GetSkinWeights (_obj ):
164+ def pybind11_GetSkinWeights_reference_internal (_obj ):
165+ return SkinPlusPlusPymxs .get_skin_weights (_obj .Name , 5 )
150166
151- return SkinPlusPlusPymxs .get_skin_weights_np_take_ownership (_obj .Name )
167+ @timer (get_timer_dict )
168+ def pybind11_GetSkinWeights_automatic (_obj ):
169+ return SkinPlusPlusPymxs .get_skin_weights (_obj .Name , 6 )
152170
171+ @timer (get_timer_dict )
172+ def pybind11_GetSkinWeights_automatic_reference (_obj ):
173+ return SkinPlusPlusPymxs .get_skin_weights (_obj .Name , 7 )
153174
154- set_timer_dict : dict [str , tuple [float , Any ]] = {}
175+ set_timer_dict : dict [str , tuple [float , Any , str ]] = {}
155176@timer (set_timer_dict )
156177def mxs_SetSkinWeights ( _obj , _boneIDs , _weights ):
157178 return SetSkinWeights (_obj , _boneIDs , _weights )
@@ -172,26 +193,22 @@ def cpppf_SetSkinWeights( _obj, _boneIDs, _weights):
172193obj = mxRt .GetNodeByName ("Sphere001" )
173194
174195get_function_list = (
175- # pymxs_GetSkinWeights,
176- # mxs_GetSkinWeights,
177- # cppfp_GetSkinWeights,
178- # cpppm_GetSkinWeights,
179- # cpppf_GetSkinWeights,
196+ pymxs_GetSkinWeights ,
197+ mxs_GetSkinWeights ,
198+ mxs_GetSkinWeights_NP ,
199+ cppfp_GetSkinWeights ,
200+ cpppm_GetSkinWeights ,
201+ cpppf_GetSkinWeights ,
180202 pybind11_GetSkinWeights ,
181- pybind11np_GetSkinWeights ,
182- pybind11npmove_GetSkinWeights ,
183- pybind11nptakeownership_GetSkinWeights ,
184- # lambda: pybind11np_GetSkinWeights(obj),
203+ pybind11_GetSkinWeights_take_ownership ,
204+ pybind11_GetSkinWeights_copy ,
205+ pybind11_GetSkinWeights_move ,
206+ pybind11_GetSkinWeights_reference ,
207+ pybind11_GetSkinWeights_reference_internal ,
208+ pybind11_GetSkinWeights_automatic ,
209+ pybind11_GetSkinWeights_automatic_reference ,
185210)
186211
187- # weights = [(0.5, 0.5) for _ in range(obj.Verts.Count)]
188- # ids = [(1, 2) for _ in range(obj.Verts.Count)]
189- # set_function_list = (
190- # lambda: mxs_SetSkinWeights(obj, weights, ids),
191- # lambda: cppfp_SetSkinWeights(obj, weights, ids),
192- # lambda: cpppm_SetSkinWeights(obj, weights, ids),
193- # lambda: cpppf_SetSkinWeights(obj, weights, ids),
194- # )
195212
196213set_loops (1 )
197214def run_functions (function_list , _obj ):
@@ -202,15 +219,15 @@ def run_functions(function_list, _obj):
202219 print (type (result ))
203220 print (len (result ))
204221
205- def process_results (time_data : dict [str , tuple [float , Any ]] ):
206- times = []
207- values = []
208- for time , value in time_data .values ():
209- times . append ( time )
210- values . append ( value )
211-
212- max_time = max (times )
213- for function_name , ( time , value ) in time_data . items () :
222+ def process_results (time_data : " dict[str, tuple[float, Any, str]]" ):
223+ # times = []
224+ # values = []
225+ data = list ( time_data .values ())
226+ data . sort ( key = lambda x : x [ 0 ] )
227+ max_time = data [ - 1 ][ 0 ]
228+ data . reverse ()
229+ # max_time = max(times)
230+ for time , _ , function_name in data :
214231 percentage_ratio = (max_time / time )
215232 message = f"{ function_name } : { time } -"
216233 if percentage_ratio == 1.0 :
@@ -223,4 +240,20 @@ def process_results(time_data: dict[str, tuple[float, Any]]):
223240run_functions (get_function_list , obj )
224241process_results (get_timer_dict )
225242
226- # print(np_GetSkinWeights())
243+
244+ | Function | Time - secs | x Faster | % Faster |
245+ | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | - - - - - - - - - - - - - - - - - - - - - | - - - - - - - - - - - - - - - - - - - - - - | - - - - - - - - - - - - - - - - - - - - - - |
246+ | pymxs_GetSkinWeights | 20.34769090000009 | base line | base line |
247+ | mxs_GetSkinWeights_NP | 15.51825759999997 | 1.3112097649416599 x | 131.12097649416597 % |
248+ | mxs_GetSkinWeights | 14.42323169999986 | 1.4107580966060669 x | 141.0758096606067 % |
249+ | cpppf_GetSkinWeights | 7.435437399999955 | 2.7365829076847867 x | 273.65829076847865 % |
250+ | cppfp_GetSkinWeights | 6.338866400000143 | 3.2099889185232917 x | 320.99889185232917 % |
251+ | cpppm_GetSkinWeights | 5.98266609999996 | 3.4011075597216136 x | 340.11075597216137 % |
252+ | pybind11_GetSkinWeights_automatic | 1.2681291999999758 | 16.045439928360988 x | 1604.5439928360988 % |
253+ | pybind11_GetSkinWeights_move | 1.09791139999993 | 18.533090101807293 x | 1853.3090101807293 % |
254+ | pybind11_GetSkinWeights_copy | 0.9864563000000999 | 20.627057579740764 x | 2062.7057579740763 % |
255+ | pybind11_GetSkinWeights | 0.9028401000000486 | 22.537424844110262 x | 2253.7424844110265 % |
256+ | pybind11_GetSkinWeights_reference_internal | 0.4243109000001368 | 47.954674037347445 x | 4795.467403734745 % |
257+ | pybind11_GetSkinWeights_automatic_reference | 0.4236172999999326 | 48.03319151508526 x | 4803.3191515085255 % |
258+ | pybind11_GetSkinWeights_take_ownership | 0.41753419999986363 | 48.73299217167536 x | 4873.299217167536 % |
259+ | pybind11_GetSkinWeights_reference | 0.41740709999999126 | 48.747831313843285 x | 4874.783131384329 % |
0 commit comments