Why is betapdf so slow?
1 次查看(过去 30 天)
显示 更早的评论
I'm running some code where I need to evaluate several beta pdfs per iteration. When I profile my code I notice that the four calls to betapdf consume about one-third (0.012s out of 0.03s total) of the run-time.
It seems that betapdf is implemented as an .m file rather than mex. Is there a mex'ed (or just faster) version of betapdf out there?
2 个评论
James Heald
2020-7-17
i also need a faster version of this. it is prohibitively slow for the arrays im working with. it is about 10 x slower than normpdf
Jeff Miller
2020-7-19
Cupid is a bit faster if the distribution parameters are fixed:
n = 1000000;
a = 3;
b = 2;
x = betarnd(a,b,n,1);
tic
xpdf = betapdf(x,a,b);
toc
% Elapsed time is 0.306104 seconds.
cupidbeta = Beta(a,b); % Using Cupid
tic
xpdfcupid = cupidbeta.PDF(x);
toc
% Elapsed time is 0.090670 seconds.
回答(1 个)
John D'Errico
2015-12-9
betapdf is as it is, because it is. Writing it as an m-file versus a mex-ed file has advantages, but also disadvantages. Yes, were MATLAB composed of entirely compiled code, those compiled pieces would usually run faster. At the same time, m-code is easier to read, easier to debug, easier to change if at some point in the future they wanted to do something.
Since I would expect that few people are that worried about the brute speed of beta pdf evaluation, they chose to leave it in an m-file form.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!