My question is why in matlab square takes more time than multiplication. I read an article, say, square actually can be done a little bit quicker than multiplication. But the test code below doesn't support this. So how does Matlab implement square(and other integer power, which I'm also interested in)? The test code is following:
a=1; tic; for k=1:10000 b=a*a; end toc;
Then, without any changes except "b=a*a" is changed into "b=a^2":
a=1; tic; for k=1:10000 b=a^2; end toc;
Consequently, multiplication takes about 77 microseconds while square takes 500+.
Thanks in advance!! Jerry