performance - More on using i and j as variables in Matlab: speed -


the matlab documentation says that

for speed , improved robustness, can replace complex , j 1i. example, instead of using

a = i; 

use

a = 1i; 

the robustness part clear, as there might variables called i or j. however, speed, have made simple test in matlab 2010b , obtain results seem contradict claim:

>>clear  >> a=0; tic, n=1:1e8, a=i; end, toc elapsed time 3.056741 seconds.  >> a=0; tic, n=1:1e8, a=1i; end, toc elapsed time 3.205472 seconds. 

any ideas? version-related issue?

after comments @tryhard , @horchler, have tried assigning other values variable a, these results:

increasing order of elapsed time:

"i" < "1i" < "1*i" (trend "a")

"2i" < "2*1i" < "2*i" (trend "b")

"1+1i" < "1+i" < "1+1*i" (trend "a")

"2+2i" < "2+2*1i" < "2+2*i" (trend "b")

i think looking @ pathological example. try more complex (results shown r2012b on osx):

(repeated addition)

>> clear >> a=0; tic, n=1:1e8, = + i; end, toc elapsed time 2.217482 seconds. % <-- slower >> clear >> a=0; tic, n=1:1e8, = + 1i; end, toc elapsed time 1.962985 seconds. % <-- faster 

(repeated multiplication)

>> clear >> a=0; tic, n=1:1e8, = * i; end, toc elapsed time 2.239134 seconds. % <-- slower >> clear >> a=0; tic, n=1:1e8, = * 1i; end, toc elapsed time 1.998718 seconds. % <-- faster 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -