#

A Tour of NTL: Tips for Getting the Best Performance out of NTL

1. Make sure you run the configuration wizard when you install NTL. This is the default behaviour in the makefile in the Unix distribution, so don't change this; in the Windows distribution, there is unfortunately no easy way to run the wizard.

2. In time-critical code, avoid creating unnecessary temporary objects. For example, instead of

   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.

   NOTE: actually, for the class `ZZ`, there is a special function `MulAddTo`, with whic one can write the loop body simply as

          MulAddTo(res, a[i], b[i]);

3. If you use the class `ZZ_p`, try to avoid switching the modulus too often, as this can be a rather expensive operation. If you must switch the modulus often, use the class `ZZ_pContext` to save the information associated with the modulus (see ZZ_p.txt). The same holds for analogous classes, such as `zz_p` and `GF2E`.