part(text, n:$) is very slow. Patch attached
@sgougeon)
Reported by Samuel GOUGEON (%ip_part.sci (1.90 KB, text/x-csrc)
%ip_part.sci optimized
BUG DESCRIPTION:
----------------
Actually, the initial implementation of %ip_part() posted there: http://bugzilla.scilab.org/show_bug.cgi?id=10816#c2 did not check the implicit polynomial input param. This was on purpose. This checking was added during the review in Patch set #2 at https://codereview.scilab.org/#/c/12396/
Yet, it is useless. Indeed,
a) the second argin is necessarily an implicit polynomial, since otherwise the routing would not have targetted the %ip_part overload.
b) the polynomial variable does not need to be "$". Any other variable would also work, as in: part(text, 3:%z)
This useless checking slows down the script by a factor of 30 to 50! (likely due to the compilation of 2 local functions at each call).
These functions could be removed. Replacing them by direct tests is useless, as discussed above.
Finally, profiling %ip_part shows that the call to unique() is also quite lengthy. This is why, for small arrays of strings, avoiding the factorization allowed by unique() is actually faster.
The optimized script is attached. It is ~40x faster than the current release.