atand(x) very much slower than atan(x)!?

2 ビュー (過去 30 日間)
Ernst Jan
Ernst Jan 2013 年 3 月 28 日
Today I used atand(x) and atan(x). To my great surprise atand(x) was not just a little bit slower than atan(x) but is incredibly slow compared to atan(x)?
I tried to verify this by using the code below. First a time measurement for atan(x), than for atan(x) multiplied with 360/2/pi to go to degrees and finally one loop for atand(x). The results I found were:
Elapsed time is 0.047019 seconds. -> atan(x)
Elapsed time is 0.062016 seconds. -> atan(x)*360/2/pi
Elapsed time is 4.166911 seconds. -> atand(x)
And finally a test to check if atand(x) yielded identical results to atan(x) which was 'true' for all arguments tested.
This would mean that one should never use atan2d because atan2(x)*360/2/pi is much and much quicker? Why is there even a atan2d(x) function or why is it so slow?
Kind regards,
Ernst Jan Grift
clear all
n=1000000;
x_rad=zeros(1,n);
x_rad_to_d=zeros(1,n);
x_d=zeros(1,n);
arg=rand(1,n);
tic
for i=1:n
x_rad(i)=atan(arg(n));
end
toc
tic
for i=1:n
x_rad_to_d(i)=atan(arg(n))*360/2/pi;
end
toc
tic
for i=1:n
x_d(i)=atand(arg(n));
end
toc
same=x_rad_to_d==x_d;
all(same)

採用された回答

Sean de Wolski
Sean de Wolski 2013 年 3 月 28 日
I don't see any record of this; please file an enhancement request.
  1 件のコメント
Ernst Jan
Ernst Jan 2013 年 3 月 28 日
A service request has been submitted. Both atand(x) and atan2d(x) show this slow behaviour.

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2013 年 3 月 28 日
編集済み: Matt J 2013 年 3 月 28 日
Your observation is interesting, but I don't think the conclusion is that you should never use ATAND, but only that it hasn't been well-optimized for the JIT yet, and shouldn't be used in for-loops. When vectorized, its performance is fine,
n=1e7;
arg=rand(1,n);
tic
x_rad=atan(arg);
toc
%Elapsed time is 0.106370 seconds.
tic
x_rad_to_d=atan(arg)*180/pi;
toc
%Elapsed time is 0.111417 seconds.
tic
x_d=atand(arg);
toc
%Elapsed time is 0.115595 seconds.

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by