# HP Forums

Full Version: HP Prime vs HP71 benchmark
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I finished my random Pi program and compared the Prime and HP71.

Here is the prime program:
Code:
``` EXPORT PITWO() BEGIN H:=0; T:=0; RANDSEED(1); S:=Ticks; WHILE 1 DO T:=T+1; X:=RANDOM()^2+RANDOM()^2; IF X<= 1 THEN H:=H+1; END; IF T MOD 10000 = 0 THEN E:= TICKS-S; PRINT("T:"+T+" PI:"+4*H/T+" E:"+E); END; END; END;```

Basically you generate two random numbers and see if it is within the radius of a circle. The ratio of the number of points inside the circle and all the points is pi/4.

For 50,000 pairs:
HP71: Pi=3.14592; Time: 8370 seconds
Prime: Pi=3.14592; Time 8.732 seconds

The prime was 960 times faster than the HP71, which I guess is not really a surprise, given the clock ratio is about 640. (Unlike the HP71, I cannot get an exact clock speed for my prime - no peek() function). The calculations appear to be identical - even to the random numbers generated.
(01-20-2017 08:35 PM)KeithB Wrote: [ -> ]I finished my random Pi program and compared the Prime and HP71.

Here is the prime program:
Hi, very interesting ... would you show us the program of the HP71B? Could be interesting how fast the calc with the HP71B FORTH would be?

regards
Erwin
Here is the 71B program:

Code:
``` 10 H=0 20 T=0 30 RANDOMIZE 1 40 S=TIME 50 T=T+1 60 X=RND^2 + RND^2 70 IF X<= 1 THEN H=H+1 80 IF MOD(T,10000) = 0 THEN DISP USING 90; T/1000, 4*H/T, TIME-S 90 IMAGE DD,"KPI:", D.DDDDD, "ET:",DDDD.D 100 GOTO 50```

I have a FORTH module, so if you have a FORTH word to run, I would be glad to try.

ETA: I guess I could try assembler, too.
I just got the results using the CAS rand() function.

For 50,000 pairs:
Pi = 3.13752 Time = 59.752 seconds, or almost 7X slower than RANDOM().
Hello,

The most surprising thing is that Prime is not much faster than the 71.

Prime runs at 400Mhz, I do not know how fast the 71 runs....
However, the 71, being based on a Saturn CPU also has slow instructions (ie, the instructions can take up to 15 or 20 CPU cycles to execute). Most Prime CPU instructions only take 1 cycle....

However, the Prime programming language will be much less efficient than the 71 as the 71 interpreted does not need to do any type of memory allocation or things like that while the prime will have to do a LOT of them.

BTW, you can optimize the Prime program as follow: It will run around 1.5 times faster I think...
EXPORT PI2()
BEGIN
H:=0;
T:=0;
S:=Ticks;
RANDSEED(1);
WHILE 1 DO
for A:= 1 to 10000 DO
H:= H+IP(RANDOM()^2+RANDOM()^2);
end;
T:= T+10000;
E:= TICKS-S;
PRINT("T:"+T+" PI:"+4*(T-H)/T+" E:"+E);
END;
END;
Clever! I like the IP() trick!

Note that the Prime was faster than a naïve comparison of clocks would suggest.
Thanks cyrille.
But you have a bug*. H is supposed to be the number of hits *inside* the circle, not outside. I had to add an extra count and subtract that from 10000 to get things to work.

Anyway, that does speed things up as you said, it now takes about 5.1 seconds for 50000 iterations. That makes the prime about 1650 times faster than the HP71.

BTW, what is up with the 'C like' for loop? It works without a syntax error, but is not documented. Is any expression allowed in the place of the from?

ETA: OOPS, I did not see that you had corrected the PI calculation to correct for this, sorry.
(01-24-2017 04:32 PM)KeithB Wrote: [ -> ]BTW, what is up with the 'C like' for loop? It works without a syntax error, but is not documented. Is any expression allowed in the place of the from?

The for statement is documented which statement are you referring to?

Tom L
The fact that he uses:

FOR A:=1 TO 10000 DO

FOR A FROM 1 TO 10000 DO

Leaving out the FROM is not documented.
(01-24-2017 06:13 PM)KeithB Wrote: [ -> ]The fact that he uses:

FOR A:=1 TO 10000 DO

FOR A FROM 1 TO 10000 DO

Leaving out the FROM is not documented.

Ha! You're right! I come from a BASIC background so I never even thought of putting FROM in there. I've always used the undocumented version. Maybe I should read the manual more often!

Tom L
Hello,

Yes, both form do work....

Remember, you can also do a step and a downto in a for...

Cyrille
How does the WP 34S cope with this problem???

Pauli
What problem?
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :