Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Efficiency of the colon operator in Mata

From (William Gould, Stata)
Subject   Re: st: Efficiency of the colon operator in Mata
Date   Mon, 22 May 2006 10:23:13 -0500

Ben Jann <> 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
*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index