[HP35s] Fastest way to increment a variable
|
04-29-2019, 03:13 PM
(This post was last modified: 05-06-2019 08:56 AM by fred_76.)
Post: #1
|
|||
|
|||
[HP35s] Fastest way to increment a variable
Hello
There are several ways to increment an integer variable by 1. But some are faster than others. First of all, the "most common one", which is the base time : Code:
With the slow equations : Code:
The ugly one : Code:
After an idea of Csaba, the counter is stored in the stat pile (to be recalled by the function [SUMS][n]) : Code:
Note that the CLSTK is required for time effectiveness as Σ+ runs faster when the registers x=y=0. If you want to be more friendly with the pile, use CLx instead of CLSTK, you will loose about 2 ms but it will be better for the pile's health ! If you don't use CLSTK or CLx, the execution time of Σ+ with x,y<>0,0 will take about 42 ms. The official alternative : Code:
The unexpected but quite fast one : Code:
If you agree to store constants in variables (here 1 in N), then : Code:
These are some ways to optimize the execution time on slow machines, like the HP35s, especially if those instructions are repeated hundreds of times. As a conclusion : RCL N | STO+V = 14 ms RCL V | NOT | +/- | STO V = 22 ms ISG V | Dummy line = 31 ms CLSTK | Σ+ = 37 ms 1 | STO+V = 37 ms CLx | Σ+ = 39 ms Σ+ = 42 ms RCL V | 1 | + | STO V = 49 ms EQN 1+V►V = 125 ms Fred |
|||
04-29-2019, 06:18 PM
Post: #2
|
|||
|
|||
RE: [HP35s] Fastest way to increment a variable
(04-29-2019 03:13 PM)fred_76 Wrote: The unexpected and quite fast one : Is NOT the bitwise negation operator ? (instead of logical NOT, returning 0, 1) What range of integers until above not work anymore ? Some 2^n powers ? If the order NOT +/- is switched, does it decrement the number ? If true, that make the code *very* unreadable ... |
|||
04-29-2019, 06:51 PM
(This post was last modified: 04-29-2019 06:57 PM by Csaba Tizedes.)
Post: #3
|
|||
|
|||
RE: [HP35s] Fastest way to increment a variable | |||
04-30-2019, 07:23 AM
Post: #4
|
|||
|
|||
RE: [HP35s] Fastest way to increment a variable | |||
04-30-2019, 07:56 AM
Post: #5
|
|||
|
|||
RE: [HP35s] Fastest way to increment a variable
(04-29-2019 06:18 PM)Albert Chan Wrote:(04-29-2019 03:13 PM)fred_76 Wrote: The unexpected and quite fast one : Yes, 36-bit bitwise negation. Quote:What range of integers until above not work anymore ? Some 2^n powers ? 2's complement range [-(2^35), 2^35-1]. Quote:If the order NOT +/- is switched, does it decrement the number ? Yes. E.g.: "0 +/- NOT" produces -1. — Ian Abbott |
|||
04-30-2019, 08:28 AM
(This post was last modified: 04-30-2019 10:47 AM by Csaba Tizedes.)
Post: #6
|
|||
|
|||
RE: [HP35s] Fastest way to increment a variable
(04-30-2019 07:23 AM)grsbanks Wrote:(04-29-2019 06:51 PM)Csaba Tizedes Wrote: 2a.) Please test 0 SUM+ (this increases stat variable n) OR Yes, it is obvious, but with this you can add and count in one step and you have a possibility to count back and stop without counter==zero condition checking (eg. with an error): Code:
BTW: on my 20S 1 STO+ var and 1 SUM+ speed ratio is 2.05, it is good profit for the additional benefits. Csaba |
|||
04-30-2019, 01:18 PM
(This post was last modified: 04-30-2019 03:27 PM by fred_76.)
Post: #7
|
|||
|
|||
RE: [HP35s] Fastest way to increment a variable
(04-29-2019 06:51 PM)Csaba Tizedes Wrote: Two notes: Csaba, As the HP35s does not have a timer, I had to measure manually with this code : Code:
I first measured the time for the empty loop, 10 times and I retain the median time = T0 (=21.80 s) I then measure the time for the tested function, 5 times, retaining the median time = Tf The execution time for the tested function is then : Tef = (Tf-T0)/500*1000 in ms For example : function = x² - Tf = 27.07 s >> Tef = (27.07-21.80)/500*1000=10.54 ms (04-29-2019 06:51 PM)Csaba Tizedes Wrote: Two notes: --- edited ---- [SUM+] is [Σ+] on the HP35S and take 42.1 ms to execute. This is far more than [STO+ var] with 9.1 ms. To recall the number of samples from the stat pile, we have to call the function [n] which takes 4.8 ms to execute, a bit faster than [RCL var] with 5.1 ms. I tested Code:
Code:
Note that Σ+ runs faster when x = 0 (34 ms) and even faster when also y=0 (30 ms) so the CLSTK. Code:
|
|||
04-30-2019, 01:26 PM
(This post was last modified: 04-30-2019 01:29 PM by fred_76.)
Post: #8
|
|||
|
|||
RE: [HP35s] Fastest way to increment a variable
(04-29-2019 06:18 PM)Albert Chan Wrote:(04-29-2019 03:13 PM)fred_76 Wrote: The unexpected and quite fast one : On the HP35s, it works until you overflow the precision of 12 digits, ie within the range of : -999 999 999 999 ; +999 999 999 999 |
|||
04-30-2019, 01:49 PM
Post: #9
|
|||
|
|||
RE: [HP35s] Fastest way to increment a variable
(04-30-2019 01:18 PM)fred_76 Wrote:(04-29-2019 06:51 PM)Csaba Tizedes Wrote: 1.) How you measured? I had the same question as Csaba and I liked your answer, Fred. The timing aspect was as interesting to me as the incrementation results themselves. Thanks! |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)