On Mon, 22 Feb 2016, Allin Cottrell wrote:
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.
And besides, you can just scrap the "else" clause for your Hansl loop and
get some extra performance. After doing so, I too get an order of
magnitude of about 10:1, which isn't bad.
It's interesting to note that for smaller array sizes (say, if your
trim your array from 17 items to 12-13), hansl actually outperforms
Python, which I find very surprising.
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------