mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -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_)
|
||||
|
||||
Reference in New Issue
Block a user