On Mon, 22 Feb 2016, Henrique Andrade wrote:
Dear Jack,
Thanks a lot for your help! I'm almost finishing my function and I'm
doing some performances comparisons with Python here on my Windows 7
PC (RAM: 8 GB; CPU: Core i5 3.2 GHz) and I think Hansl is not
performing well:
timeHansl = 64.698732
timePython = 0.67678400
Never use $i, $j and so on in loops, unless you really need string
substitution. It prevents gretl from "compiling" your code.
If I rewrite your printing loop as
# look this up once, not n times
scalar cp = cols(P)
loop i = 1..rows(P) --quiet
loop j = 1..cp --quiet
if P[i, j] = 1
P_S = P_S ~ " " ~ S[j]
else
P_S = P_S ~ ""
endif
endloop
print P_S
P_S = ""
endloop
the hansl time on my machine drops from 22 seconds to 5.5. That's
against 0.65 for python, but then the itertools module is optimized
for just this sort of problem.
Allin