Slight n-queens benchmark speedup for Casio fx-4000P, fx-7000G, etc. - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: Not HP Calculators (/forum-7.html) +--- Forum: Not quite HP Calculators - but related (/forum-8.html) +--- Thread: Slight n-queens benchmark speedup for Casio fx-4000P, fx-7000G, etc. (/thread-14587.html) Slight n-queens benchmark speedup for Casio fx-4000P, fx-7000G, etc. - Dave Britten - 02-29-2020 05:00 PM By making use of the automatic Ans variable, and playing a bit fast and loose with the parser, it's possible to squeeze a bit more speed out of the n-queens program for the fx-4000P, and presumably most (all?) of the models that use the same benchmark program. Modified version: Code: ```        Mcl         8->R  Lbl 0  X=R=>Goto 4         Isz X         R->A[X]  Lbl 1  Isz S         X->Y  Lbl 2  Dsz Y Deg         Y=0=>Goto 0         A[X]-A[Y         Ans=0=>Goto 3         X-Y<>Abs Ans=>Goto 2  Lbl 3  Dsz A[X] Goto 1         Dsz X Goto 3  Lbl 4  S``` By omitting the store into variable T, and instead letting A[X]-A[Y (omission of the final bracket is deliberate) automatically store in Ans, the execution time on my fx-4000P dropped from 00:05:57 to 00:05:41 (+/- 1 sec. margin of error on measurements). So, roughly a 4.5% reduction in execution time. Note that you can't leave out the closing bracket for array references that are the target of a store or Dsz/Isz, so R->A[X] and Dsz A[X] can't benefit from this optimization. Now somebody needs to go re-test the FX-6000G, FX-6300G, FX-6500G, FX-7000G, FX-7000GA, FX-7000GB, FX-7200G... RE: Slight n-queens benchmark speedup for Casio fx-4000P, fx-7000G, etc. - Dave Britten - 03-01-2020 01:22 PM I found another big speedup: removing the Goto 3 that only jumps over a single line, and replacing it by just inverting the conditional test got the total execution time down to 00:05:20, or about a 10.4% speedup over the original. Code: ```        Mcl         8→R  Lbl 0  X=R⇒Goto 4         Isz X         R→A[X]  Lbl 1  Isz S         X→Y  Lbl 2  Dsz Y Deg         Y=0⇒Goto 0         A[X]-A[Y         Ans≠0⇒X-Y≠Abs Ans⇒Goto 2  Lbl 3  Dsz A[X] Goto 1         Dsz X Goto 3  Lbl 4  S``` I also put in the appropriate unicode arrows and not-equals, but that doesn't speed up the calculator. RE: Slight n-queens benchmark speedup for Casio fx-4000P, fx-7000G, etc. - xerxes - 03-01-2020 07:48 PM Thank you for the nice optimization, but I'm afraid it's not possible to use it for the list, because that would mean to retest many devices (not only the CASIOs) with the same optimization. I've dissolved my collection in the meanwhle and so I'm not able to retest all of them. I think it's not really a problem, because the old test code is sufficient enough for comparing the relative speed for the same algorithm.