Working on Fusc series example, I found something disturbing with my code on mstack (the stack of values). Sometime we didn't find the "useless" code, until that has a cost on performance. Here I use something which I found normal. to add an index number to the method add on a VB6 collection, to just append data (the Data statement of M2000 append data to the "end of list", while the Push statement add to the top, where we pop data, so using Push and Number we pop numbers in a LIFO manner, and using Data and Number we use the stack of values in a FIFO manner). Using the index number to place after the value cause the VB6 collection to iterate through all items; For a small number of items that isn't something to notice. But for some 100k of data this getting worse and more worse, The vb6 collection has two pointers internal to add items from the two ends of a series of data. So using the add method without index number to put after this the data means we append the data (to the right end, when left end has the first item). The add like this is with no cost O(1).
The new revision has 5 additions/fixes. So see at the Git the readme.txt
This program runs for 3.3 minutes, and 33 minutes on previous revision (before the fix).
module Fusc_sequence (level) {
class z {
boolean noStop=true
module generate(&k()) {
object q=stack:=1
call k(0)
call k(1)
stack q {
x=number:data x:call k(x)
x+=stackitem():data x:call k(x)
if .noStop then loop
}
q=stack
.noStop<=true
}
}
z=z()
long max=61, n, k=-1, m
string fmt="#,##0", fs="{0:-10} : {1}", prev
function f1(new x) {
n++
if n=1 then print "First 61 terms:":print "[";
if n<max then
print x+", ";
else.if n=max then
print x+"]"
z.noStop=false
end if
}
profiler
z.generate lazy$(&f1())
print "Points in the sequence where an item has more digits than any previous items:"
print format$(fs, "index", "value")
n=0: max=level
function f2(new x) {if x>=k then m++:k=10&**m:print format$(fs,str$(n,fmt),str$(x,fmt)):if m=max then z.noStop=false
n++}
z.generate lazy$(&f2())
print timecount
}
Fusc_sequence 5
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου
You can feel free to write any suggestion, or idea on the subject.