Thank you for the replies. As you said, the significance really depends on the size of the matrices. But the efficient matrix pre-allocation seems to be a cleaner way of programming as well -- at least to me :-)

Best,
Artur


2014-03-27 15:44 GMT+01:00 Riccardo (Jack) Lucchetti <r.lucchetti@univpm.it>:
On Thu, 27 Mar 2014, Cottrell, Allin wrote:

Having done an experiment I'm actually quite surprised at just how much faster
option 2 is. Here's my test:

You shuld also consider the "loop" overhead. Try this:

<hansl>
set echo off
set messages off

loop i=1..10 --quiet
    matrix X$i = mnormal(200,20)
endloop


# option 1

set stopwatch
loop 100 --quiet
    matrix A = X1 ~ X2 ~ X3 ~ X4 ~ X5 ~ X6 ~ X7 ~ X8 ~ X9 ~ X10
endloop
t0 = $stopwatch

set stopwatch
loop 100 --quiet
    matrix A = {}
    loop i=1..10 --quiet
        A = A ~ X$i
    endloop
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@univpm.it
  http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------
_______________________________________________
Gretl-users mailing list
Gretl-users@lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users