02/23/2023, 07:08 PM
(02/23/2023, 05:08 PM)Gottfried Wrote:(02/23/2023, 04:30 PM)JmsNxn Wrote: E =
For X = 0, 500:
For Y=0, 500:
WRITE(X,Y)
(...)
Mike3's time would be written:
MIKE =
For X=0,500:
For Y=0, 500:
P = F(X,Y);
WRITE(P);
(...)
Hmm, I cannot go deep into it. But when I optimized Mike3's procedure my first rewriting was to replace the "write(element)" by something like "write(vector-of-elements)" because the Pari/GP-internal implementation of the elementwise "write()" is extremely time-consumptive. So for instance it would be better to put the elements using "Str()" into a string-variable, and then you can with one (of this time-consumptive) "write()" deliver the whole line to the file. You might even construct the file-image as complete string including the "\n"-linefeeds and deliver this with one "write()"-call at all.
In the new versions of Pari/GP there is moreover a low-level "filewrite()" which has a cache in the background and performs much faster than all procedures which call "write()" in a loop.
Something more perhaps ... but have not much time at the moment...
Okay, I believe I understand what you are saying, Gottfried.
An even faster speed up, would be to take:
Xn = X[j+1], X[j+2],..., X[j+n]
Yn = Y[j+1], Y[j+2],..., Y[j+n]
Where now we string them as a speed up on the WRITE function Pari has. Instead of writing:
For j =1, n: WRITE X[j+n];
We instead write:
WRITE(Xn)
Where, I have made my code too slow, because it depends on running the WRITE command too many times. And running the WRITE command takes time. You are saying; create the string, then reduce the amount of times we need to run the WRITE command.
I never thought of that before. My code, is more so, just a mathematical speed up. So if you assume that WRITE takes O(1) time. This means my code is mathematically faster. But WRITE does have some fuck ups. So you're definitely right!!!!!
We compile the values of a larger string; and write less often. And this increases the speed of the program!

