diff --git a/applications/test/integerPow/Make/files b/applications/test/integerPow/Make/files new file mode 100644 index 0000000000..8e07339c39 --- /dev/null +++ b/applications/test/integerPow/Make/files @@ -0,0 +1,3 @@ +Test-integerPow.C + +EXE = $(FOAM_USER_APPBIN)/Test-integerPow diff --git a/applications/test/integerPow/Make/options b/applications/test/integerPow/Make/options new file mode 100644 index 0000000000..e69de29bb2 diff --git a/applications/test/integerPow/Test-integerPow.C b/applications/test/integerPow/Test-integerPow.C new file mode 100644 index 0000000000..b6d58654d6 --- /dev/null +++ b/applications/test/integerPow/Test-integerPow.C @@ -0,0 +1,87 @@ +#include "cpuTime.H" +#include "Pair.H" +#include "Random.H" + +using namespace Foam; + +//- Number of calculations to do. Need 10^8-ish to get enough time (~2 seconds) +// to meaningfully compare. +static const label n = 100000000; + +//- Range of exponents to calculate. From -E to +E. Zero will be omitted so +// that we can do roots, too. At small values (<8) integer powers win. At +// larger values (>16), scalar powers do better. +static const label E = 4; + +//- Run a given power method +template +Pair run(Pow pow) +{ + Random rndGen(0); + + cpuTime time; + + scalar y = 0; + + for (label i = 0; i < n; ++ i) + { + const scalar x = rndGen.sampleAB(rootSmall, rootGreat); + const label e = + rndGen.sample01