Closed arhamchopra closed 4 weeks ago
This PR adds a new to_dict method for structs which is written fully in C++. The older python based to_dict method has been renamed to to_dict_depr.
to_dict
to_dict_depr
Motivation: The newer C++ based to_dict method is faster than the original python based to_dict method. Some timing examples are shown below:
class A(csp.Struct): a: int b: str c: bool d: float a = A(a=1, b="1", c=True, d=1.0) %timeit a.to_dict() # 0.888 microseconds %timeit a.to_dict_depr() # 4.98 microseconds class E(csp.Struct): a: list b: dict c: tuple d: set e = E(a=[1,2,3], b={1:1, 2:2, 3:3}, c=(1,2,3), d={1,2,3}) %timeit e.to_dict() # 2.65 microseconds %timeit e.to_dict_depr() # 15.4 microseconds
This PR adds a new
to_dict
method for structs which is written fully in C++. The older python basedto_dict
method has been renamed toto_dict_depr
.Motivation: The newer C++ based
to_dict
method is faster than the original python basedto_dict
method. Some timing examples are shown below: