Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Good programming practice in Mata


From   "William Gould, StataCorp LP" <[email protected]>
To   [email protected]
Subject   Re: st: Good programming practice in Mata
Date   Mon, 02 Jul 2012 09:34:59 -0500

Gordon Hughes <[email protected]> writes, 

    [In http://www.stata.com/statalist/archive/2012-05/msg00712.html]
    the gist of the advice, as I understand it, is that it is more
    efficient to embed Mata functions in an ado file rather than
    precompile them and access them through .mo files or .mlib
    libraries [...] [which] runs completely counter to traditional good
    practice.

    [...] I understand the advice as suggesting that Stata will execute
    a program more efficiently if the production version takes the form
    of a single - or small number - of ado-files with embedded Mata
    functions and no associated .mo or .mlib files.

I need to clarify.  

    1.  Stata runs programs most efficiently when the Mata code is 
        pre-compiled and stored in a .mlib or .mo file. 

    2.  Gorden is absolutely correct when he writes that good style is
        to write general-purpose utilities and compile them into
        libraries for use by other routines.  This makes them globally 
        available and saves recompliation costs.

    3.  Nonetheless, every problem has some custom code associated with 
        solving it. 

    4.  StataCorp follows the practice of placing such custom code 
        into the ado-file.  Yes, that slows down the loading of the 
        ado-file, but not by much, and Stata is good at keeping 
        ado-files in memory, anyway, so ado-files are seldom reloaded.  
        The extra time of recompiling goes mostly unnoticed. 
        The advantages outweigh the disadvantages.  

Cheers, 

-- Bill
[email protected]
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index