Ruud H.G. van Tol on Mon, 29 Dec 2025 14:22:20 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

phrasing and performance



Some simplistic observations:

\\ square, add, divide, square = 4 ops
? for(n=1,2^18, ((n^2+n)/2)^2 );
cpu time = 66 ms, real time = 61 ms.  \\ <- fastest

? ((n^2+n)/2)^2
%2 = 1/4*n^4 + 1/2*n^3 + 1/4*n^2

\\ (power,divide,multiply)*3, add*2 = 11 ops
? for(n=1,2^18, 1/4*n^4 + 1/2*n^3 + 1/4*n^2 );
cpu time = 156 ms, real time = 158 ms.  \\ <- slowest

\\ (power,divide)*3+add*2 = 8 ops
? for(n=1,2^18, n^4/4 + n^3/2 + n^2/4 );
cpu time = 122 ms, real time = 121 ms.


Guessing:
11/4 (ops) is about 158/61 (seconds).
Idem 8/4 vs 121/61.

-- Ruud