Ben Jann <ben.jann@soz.gess.ethz.ch> did some speed tests in Mata
and diiscovered that
if (length(k)==1) y = x * k
else y = x :* k
is faster than
y = x :* k
(In Ben's code, k is a vector or scalar).
Ben wonders,
Can anyone confirm these results? Is it true that the colon operator
significantly slows down computations if used in situations where it is
not really needed or is this just an artifact produced by my local
machine?
I remind Ben, we have already discovered that Ben's computer is
particularly
slow at running colon operators. Most computers are not, but a particular
older modern of the Intel chip is, and we have duplicated the behavior
here.
We at StataCorp even know how to get around the problem, but our concern
is
that the fix will cause modern computers to run colon operators slower.
We
said we would test, but we have not completed that yet.
In any case, whenever Ben can avoid colon operators, he is going to
observe
better performance. The rest of us, however, will not.
-- Bill
wgould@stata.com