On Sun, 28 May 2017, Marcin Błażejowski wrote:
Jack,
it's briliant - as usual.
Thans a lot!!!
Thanks. However, it seems that a loop-based version is actually faster
(much to my surprise):
<hansl>
set verbose off
function scalar find_0(matrix a, scalar column, scalar target)
n = rows(a)
sel = a[,column] .= target
c = selifr(seq(1,n)'~a, sel)
return c[1,1]
end function
function scalar find_1(matrix a, scalar column, scalar target)
n = rows(a)
chk = 0
i = 1
loop while !chk --quiet
chk = a[i++,column] == target
endloop
return i-1
end function
n = 100000
a = mrandgen(i,1,1000,n,2)
target = 365
column = 1
set stopwatch
loop 1000
find_0(a, column, target)
endloop
t0 = $stopwatch
loop 1000
find_1(a, column, target)
endloop
t1 = $stopwatch
print t0 t1
</hansl>
-------------------------------------------------------
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
-------------------------------------------------------