            *** PRECISE EXECUTION TIMING for SX and GX ***

People have been talking about how long various functions and
operation take to execute.  Here are some insanely accurate timers
that you can keep handy in your HP48.

PROGRAMS:

         XT   - eXecution Time, for HP 48S/SX, in ticks
         XTS  - same, but in seconds (to .001 sec)
         XTG  - for G/GX, in ticks
         XTGS - same, but in seconds (to .001 sec)

INSTRUCTIONS:

         Place object(s) on stack that you wish to time, and run the
         appropriate timer.  Ticks are returned as bare numbers;
         seconds are returned as tagged unit objects.

These timers subtract their own execution time, and are therefore very
reliable.  For example, they show that ROT ROT takes 8 ticks, whereas
3 ROLLD takes 20 ticks.  So ROT ROT is preferable to 3 ROLLD.

Although the execution time of a particular object may be constant,
these programs may sometimes seem to get differing times when run
repeatedly.  This is not a bug either of the program nor of the HP48.
Just as a 1-foot ruler randomly thrown onto a football field will span
a yardline 1/3rd of the time, so too an object that takes 1/3rd of a
clock tick will be timed as 0 ticks 2/3rds of the time, and as 1 tick
1/3rd of the time... and for exactly the same reason.

Now, if enough rulers were thrown onto a football field, like during a
freak hailstorm of rulers, we could determine their length by finding
the ratio of rulers spanning yardlines to the total number of rulers.
If 1/3rd of them span yardlines, then they're probably a foot long.
Similarly, if XT or XTG reports 13 times that an object takes 10
ticks, but reports 7 times that the same object takes 11 ticks, then
we can safely assume that it takes 10.35 ticks to execute.

In case it isn't obvious, a clock tick is not the same as a CPU clock
cycle!  A clock tick is 1/8192 of a second.  The CPU runs at about 2
MHz (SX) or 4MHz (GX).  Thus operations can take much less than one
tick to execute.

It is tempting to try to automate such an experiment by putting XT or
XTG into a loop, and finding the average number of ticks.  But this is
a flawed method.  It assumes that the timings are beginning at random
moments, like the hailstorm of rulers onto a football field.  But this
is obviously not the case.  Loops execute in a completely rhythmic
way, with a precise number of ticks between each iteration.  It's more
like a marching band that advances exactly 1.5 feet per step; if they
were to drop rulers at each step, either none would wind up spanning
yardlines, or half of them would.  By the logic described above, we'd
then conclude that the rulers are either 18-inch rulers, or infinitely
small, neither of which is even close.

So we have to start XT or XTG at truly random times in order to extend
their precision.  Using RAND WAIT won't work, because WAIT uses the
clock, and therefore always exits at a precise tick boundary.  Using
WAIT would be even worse that just a raw loop!

Using time-wasting dummy loops of random length sounds like our only
hope -- but it falls prey to the same objection as simple loops.  It
would be no different from telling the marching band to drop the
rulers after random numbers of steps instead of after every step.  The
math comes out the same.  Bummer.

So I suggest: just use them as-is, and be happy with either ticks or
milliseconds.

%%HP:T(1); @ XT, execution timer for S/SX in ticks
"D9D202BA8124F509304518BE047A2003D4303D43B21300D470E8F6018BE06B31
67E31679470CAF06ADB46AAC350BE35D534532230AAC35339201000000000000
750189A2B21305CC1"

%%HP:T(1); @ XTS, execution timer for S/SX in seconds
"D9D202BA8124F509304518BE047A2003D4303D43B21300D470E8F6018BE06B31
67E31679470CAF06ADB46AAC350BE35D534532230AAC35339201000000000000
750189A2339203000000000029180EF9A2339203000000000000010CB9A206FA
2339203000000000000010EF9A2E0A51C2A2090000F537391504A83244230C2A
20D00004596D65618E50B2130BACE"

%%HP:T(1); @ XTG, execution timer for G/GX in ticks
"D9D202BA8124F509304518BE047A2003D4303D43B21300D470E8F6018BE06B31
67E31679470CAF06ADB46AAC350BE35D534532230AAC35339201000000000000
830189A2B2130E639"

%%HP:T(1); @ XTGS, execution timer for G/GX in seconds
"D9D202BA8124F509304518BE047A2003D4303D43B21300D470E8F6018BE06B31
67E31679470CAF06ADB46AAC350BE35D534532230AAC35339201000000000000
830189A2339203000000000029180EF9A2339203000000000000010CB9A206FA
2339203000000000000010EF9A2E0A51C2A2090000F537391504A83244230C2A
20D00004596D65618E50B2130377C"

