As to type sigils on variables... Don't know how much it changes ram use or execution time. Some! Maybe look at the tokenized output difference for the space difference.
As to the multiplication versus the AND... you'd have to test. Interesting. I will try it. Speaking of testing, I'm wondering if the conditional expression is ok to avoid on the first PEEK. The intent of this is to generate a signed integer number on the range -32768 to 32767. If it goes over 32767 on any permutation of peek'd values it will fail. Probably worth generating every permutation and confirming it works. -- John. On Sat, Oct 29, 2022, 4:16 AM Eric LK <[email protected]> wrote: > "John R. Hogerhuis" <[email protected]> wrote: > > 10 DEFINTP:DEFSTRH > > 20 H=CHR$(201) > > 30 P=VARPTR(H)+1 > > 1000 P=PEEK(P)+256%*(PEEK(P+1)+256%*(PEEK(P+1)>127)) > > 1010 PRINTP > > Very nice. That seems a little more optimized than the solution I used > for my "direct file access from RAM" implementation :o) > > You could skip the second multiplication by using AND instead: > 1000 P=PEEK(P)+256%*(PEEK(P+1)-(PEEK(P+1)>127AND256)) > (Note that the sign has been reversed) but... somehow the execution > time isn't really impacted (I suppose multiplying by -1 is fast) > > FWIW, I also tried "caching" the result of "PEEK(P+1)" but again, it > didn't change the result (in all 3 implementations, 1000 iterations > took 14 seconds, so those modifications aren't really interesting, > except for the brain picking exercise ;o)). > > If I may ask a question, I almost dever used DEFINT and DEFSTR: I just > use "%" or "$" prefixes for my variables. Are DEFINT and DEFSTR faster > or is this a question of personal preferences? > > I kind of like that I can tell the type of variables by their name, > but if the other solution gives a performance boost I'm ready to > reconsider. > > Eric >
