Why is betapdf so slow?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
James Heald
el 17 de Jul. de 2020
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
el 19 de Jul. de 2020
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.
Respuestas (1)
John D'Errico
el 9 de Dic. de 2015
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 comentarios
Ver también
Categorías
Más información sobre Polynomials en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!