dss-extensions / DSS-Python

Native, "direct" Python bindings (interface) and misc tools for a custom implementation of OpenDSS (EPRI Distribution System Simulator). Based on CFFI, DSS C-API, aiming for full COM API-level compatibility on Windows, Linux and MacOS, while providing various extensions.
https://dss-extensions.org/DSS-Python/
BSD 3-Clause "New" or "Revised" License
58 stars 4 forks source link

Lists vs Arrays #13

Closed PMeira closed 1 year ago

PMeira commented 5 years ago

While some properties are faster using NumPy arrays, others that return very small arrays can be faster if they use lists. Many other properties have very similar performance. Some examples follow.

Faster with arrays (np.fromstring/np.frombuffer):

ActiveCircuit.AllBusDistances
ActiveCircuit.AllBusVmag
ActiveCircuit.AllBusVmagPu
ActiveCircuit.AllBusVolts
ActiveCircuit.AllElementLosses
ActiveCircuit.AllNodeDistances

Faster with lists (ffi.unpack):

ActiveCircuit.ActiveBus.puVLL
ActiveCircuit.ActiveBus.puVmagAngle
ActiveCircuit.ActiveBus.puVoltages
ActiveCircuit.Lines.Cmatrix
ActiveCircuit.Lines.Rmatrix
ActiveCircuit.Lines.Xmatrix
ActiveCircuit.Lines.Yprim
ActiveCircuit.Loads.ZIPV

Returning lists in some cases would probably be undesirable since the user would probably convert the list to array anyway, like ActiveCircuit.Lines.Rmatrix. In other cases, like ActiveCircuit.Loads.ZIPV, using lists could be better.

The task is to evaluate properties that would be better when used with lists while not affecting the performance negatively.

PMeira commented 1 year ago

Closing for now; I don't think a lot of properties would be better with lists.