ENH: avoid costly pow() when evaluating Polynomial

OLD timings:
    ~~~~~~~~~~~~~~~~~~
    evaluate:     -6.82572e+31 in 10.38 s
    hard-coded 0: -6.82572e+31 in 0.2 s
    hard-coded 1: -6.82572e+31 in 10.37 s
    hard-coded 2: -6.82572e+31 in 0.24 s

    New timings:
    ~~~~~~~~~~~~~~~~~~
    evaluate:     -6.82572e+31 in 0.11 s
This commit is contained in:
Mark Olesen
2010-10-08 15:56:58 +02:00
parent dcc00e2cc9
commit dd5ed76a70
3 changed files with 101 additions and 4 deletions

View File

@ -101,9 +101,12 @@ Foam::scalar Foam::Polynomial<PolySize>::evaluate(const scalar x) const
{
scalar y = this->v_[0];
for (label i=1; i<PolySize; i++)
// avoid costly pow() in calculation
scalar powX = x;
for (label i=1; i<PolySize; ++i)
{
y += this->v_[i]*pow(x, i);
y += this->v_[i]*powX;
powX *= x;
}
if (logActive_)