Tag Archives: calculator performance

Optimizing optimization code in TI-84 program

As shown in a previous installment on running the Nelder-Mead optimization of the Rosenbrock function in TI-84, its hardware is not up to the challenge for problems of this kind. It is however an interesting case to learn from this program that took a considerable amount of time (in minutes), when most TI-84 programs complete in seconds, to grasp the technique in writing optimized code.

The problem used in the setting is the Rosenbrock function:
nelder-mead-84-code-optimization3

Two techniques were used to try to optimize the code. The first one is to in-line the function (in this case the Rosenbrock function). In the original version this function is stored in a string value to be evaluated whenever necessary by using the TI-84 expr() function. The idea from common in-lining is borrowed to see if it works in TI-84. As shown in line 44 below, the Rosenbrock function replaced the original expr() function call.

nelder-mead-84-code-optimization2b

Another technique is to remove unnecessary comments. For most modern languages this is never considered a problem but for simple calculators it is speculated valuable processing time may be spent on processing comments that contribute nothing to the algorithm.
nelder-mead-84-code-optimization1

Both programs returned the same results. To compare the gain in speed, the same set of initial parameters and tolerance were used in both the original and code-optimized program. Surprisingly, the inline method does not yield any gain while removing all those “:” that were used for indentation does improve the speed. The average of the original program is 183 seconds while the program with cleaned code is only 174 seconds, which is around 95% of the run time of the original program.
nelder-mead-84-code-optimization4

 

 

 

Advertisements

Improvised semi-automatic timer to record long running Nspire calculations

In recent calculator overclocking tournaments, some programs took over more than a few minutes to finish. In extreme cases, programs run over an hour. The size of data set of these long running calculations are not realistic in most cases for hand held calculators, but for the sake of overclocking comparison, they are attempted to obtain the time required.

Instead of just watching and waiting the calculator prompt to return and stop the stopwatch, a makeshift timing device is developed with an aim to automatically record the benchmark calculation run time on the TI Nspire. The device is simple and make use of the following components:

This device works in the following way:

  • The back-light of the Nspire will be on for the whole period running the benchmark calculation.
  • When the program is finished, the back-light will turn off after a predefined period, which is a user configurable setting.
  • An LED will act as an light sensing diode, and is placed on top of the Nspire screen. The voltage will be measured by the LaunchPad, and send periodically through the 703N router to Exosite.
  • From repeated testing the difference in voltage when the back-light is on and off are determined. This make it possible to set an alarm on Exosite with that known threshold.
  • The time to start the calculation is recorded manually. After starting, the task of taking the finish time will be taken care of by the Exosite alarm timestamp, as triggered by the drop in voltage detected from the turning off of the back-light.

lighttimer4

Best result of the LED threshold is obtained when working in the evening and lights are turned off. Although the time taken is not as accurate as taken manually by stopwatch due to the delay between measuring of consecutive LED voltage (set as around 4 seconds to avoid flooding Exosite), it should be good enough for long running calculations that span a quarter to more than an hour. Better methods for timing may exists (e.g. internal timers on the Nspire itself) but this improvised one with simple devices and a free cloud service worked quite well, for the best part is automation so that I no longer have to look out from time to time to check if the calculation is finished.

Overclock Tournament Round 3

In previous rounds, Casio fx-9860GII with overclocking software Ftune2 won both rounds in a Nelder-Mead logistic curve fitting speed test, although TI Nspire CAS CX with Nover closed the gap on the second round after a little optimization on the language by declaring most variables local in scope.

In this installment, the comparison focus on the basic calculation rather than the programming environment. This simple integration equation is to be computed by both overclocked calculators:

nspire_vs_casio_sin_0_to_100_eq

Again, Casio with Ftune2 outperform the TI Nspire.nspire_vs_casio_sin_0_to_100

Nspire fight back in the overclock race

In a previous installment, fx-9860GII beats Nspire CX CAS in an overclocking match, computing the parameters for a logistic regression function by the Nelder-Mead algorithm programmed in their respective on-calculator environment. It is quite astonishing not only to see Nspire losing in the speed race, but also by how much it loses.

To give the CX a second chance, while still maintaining the overall fairness, the program on the Nspire is enhanced by localizing variables (33 of them) and nothing else. The declaration of scope for variables is believed to be a common technique for performance boost. The logic of the program remain unchanged, so is the tolerance parameter.

And the results – Nspire is catching up by doubled performance from 63 seconds to 33 seconds!

nspire_vs_casio_nelder_mead2

Casio fx-9860GII Equation Solver performance improvement by overclocking

In last installment, the Casio overclocking utility Ftune2 improved the speed performance of a Nelder-Mead program by 4.5 times. For standard calculations, more impressive results are obtained from this nice utility. In this test, the standard normal distribution function is applied in the Casio fx9860GII Equation Solver and the task is to find the Z variable (as “T” in the below screen), given the cumulative probability distribution of 0.9 (as “A” in the below screen).

casio-solver

A=1÷(√(2π))×∫(e^(-X²÷2),-999,T)

In other words, the solver’s task is to find Z from the given area of 0.9 as shaded in the below chart, which is obtained for verifying the solver’s result of 1.28155156 using the command
Graph Y=P(1.28155156).

casio-solver1

And here is the result on speed performance:

00:38 No overclocking, back-lit OFF
00:40 No overclocking, back-lit ON
00:06 Overclocked 265.42 MHz, USB OFF, back-lit OFF
00:07 Overclocked 265.42 MHz, USB OFF, back-lit ON
00:05 Overclocked 265.42 MHz, USB ON, back-lit OFF
00:05 Overclocked 265.42 MHz, USB ON, back-lit ON

The performance gain by overclocking is 7.6 to 8 times, depending whether the back-lit is on for non-overclocked runs.

For the same equation solving by the TI Nspire using nsolve(), it took 01:30 to return a result of 1.28155156555.

However, using the built-in standard functions NormCD() for the Casio and normCdf() for the TI as below

Casio fx-9860GII

A=NormCD(-999,T)

TI Nspire

nsolve(normCdf(-∞,x,0,1)=0.9,x)

both units return results instantaneously (Nspire returns 1.28155193868 while Casio returns 1.281551566).

A comparison on performance of overclocked Nspire CX CAS and fx-9860GII

Overclocking CPU is a trick to yield better performance in speed without any change to hardware or software. At clock frequency higher than those specified by the hardware manufacturer, this technique consumes more electricity as a tradeoff. This used to be referring to PC but thanks to the “openness” of modern calculators and efforts from hobbyists and developers, we are able to unlock the true power of our advanced calculators. In this case, a comparison of TI Nspire CX CAS and Casio fx-9860GII is carried out. The result is quite surprising. For the test case, a Nelder-Mead algorithm programmed in the calculators’ default on-calc programming environment is used as the benchmark. This mean no native code is used. At the same time, no special optimization is done for each of the test-beds. The program will then run a test data set to find the three parameters for a logistic regression function for a coffee shop sales prediction scenario. For fairness, the same initial set of parameters are used for the Nelder-Mead algorithm, as well as the tolerance level (1E-12). The results obtained from both calculators are verified to exact to 4 decimal places. For overclocking, the TI is running ndless with Nover 3. And the Casio is on Ftune2 v1.01. Only one overclocking performance is measured for the TI in the test which is the max stable obtainable from my hardware, 234 MHz. On the Casio, several settings are attempted, ranging from 58.98, 29.49, 117.96, 235.93, and finally 265.42 MHz. It should also be noted that the trials are done while the USB cable is plugged in, where a better performance can be obtained on overclocked Casio. Until there are definitive explanation for this, I can only speculate the Casio will be running at higher voltage while on USB and that somehow improved the performance, pretty much like the ATmel 3.3V and 5V difference. The results on performance are plotted below, with the x-axis the CPU overclocking rate and y-axis the relative performance (higher the better). nspire_vs_casio_nelder_mead1 While the Nspire CX CAS defaults at 132 MHz, the Casio already wins at 117.96 MHz by finishing the test case twice as fast. On the Nspire,1.5 times performance gain is obtained from the max overclock rate. At max overclock 265.42 MHz, the Casio runs almost 4.5 times faster than normal.

In next installment, measurements on performance by Ftune2 for the Casio will reveal the improvements by overclocking to the standard calculation functions (i.e. non-programming).