A Tour of NTL: Tips for Getting the Best Performance out of NTL
ZZ InnerProduct(const ZZ *a, const ZZ *b, long n)
{
long i;
ZZ res;
for (i = 0; i < n; i++)
res += a[i] * b[i];
return res;
}
write this as
ZZ InnerProduct(const ZZ *a, const ZZ *b, long n)
{
long i;
ZZ res, t;
for (i = 0; i < n; i++) {
mul(t, a[i], b[i]);
add(res, res, t);
}
return res;
}
The first version of InnerProduct
creates and destroys a temporary object, holding the value
a[i]*b[i], in every loop iteration.
The second does not.