Slight n-queens benchmark speedup for Casio fx-4000P, fx-7000G, etc.
02-29-2020, 05:00 PM
Post: #1
 Dave Britten Senior Member Posts: 1,916 Joined: Dec 2013
Slight n-queens benchmark speedup for Casio fx-4000P, fx-7000G, etc.
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...
03-01-2020, 01:22 PM
Post: #2
 Dave Britten Senior Member Posts: 1,916 Joined: Dec 2013
RE: Slight n-queens benchmark speedup for Casio fx-4000P, fx-7000G, etc.
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.
03-01-2020, 07:48 PM
Post: #3
 xerxes Member Posts: 111 Joined: Jun 2014
RE: Slight n-queens benchmark speedup for Casio fx-4000P, fx-7000G, etc.
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.

Calculator Benchmark
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)