Good afternoon,
It is a lot faster to populate a 100 X 100 matrix, than to populate a 10000 X 1 vectors. Why is that?
The code:
results in
So populating the square matrix is 10 times faster.
It is a lot faster to populate a 100 X 100 matrix, than to populate a 10000 X 1 vectors. Why is that?
The code:
Code:
clear all
timer on 1
matrix A = J(10000,1,.)
forvalues i=1/10000 {
matrix A[`i',1] = 1
}
timer off 1
timer on 2
matrix B = J(100,100,.)
forvalues i = 1/100 {
forvalues j = 1/100 {
matrix B[`i',`j'] = 1
}
}
timer off 2
timer list
Code:
. timer list 1: 0.33 / 1 = 0.3340 2: 0.03 / 1 = 0.0310

Comment