Closed kieh-da closed 2 years ago
Thanks for the interesting analysis. I agree, this should be linear and a runtime of more than a second is not acceptable.
I'll try to figure out, where the runtime is spent.
I can confirm the behaviour!
The major time is spent at the string concatenation (i.e. the conversion of the vector to the string) in the current line: https://github.com/DLR-SC/tixi/blob/master/src/tixiImpl.c#L1561
I exchanged strcat
with snprintf
with the appropriate concat position, and I managed to achieve linear scaling.
Using 10^5 element, I could reduce the runtime from 59 seconds down to 150 millisconds.
I managed a further runtime improvement by a factor of 2. The upper test now just takes 67 ms (originally 59 seconds) using a vector of 10^5 elements.
That's quite an improvement! Thanks for fixing the issue.
tixiAddFloatVector appears to have a computational complexity of n² (n being the number of elements in the vector), where a complexity of n should suffice. The figure below was created using Matlab R2019a with Tixi 3.1.1 (64 bit) to run tixiAddFloatVector with varying vector size n.