an HP question...
10-24-2017, 12:58 AM (This post was last modified: 10-24-2017 01:05 AM by webmasterpdx.)
Post: #11
 webmasterpdx Senior Member Posts: 541 Joined: Sep 2015
RE: an HP question...
I did some timing using TEVAL, and got some unusual results.
I used the following program:
Code:
 EXPORT T1(V,N) // Using alternate to CASE BEGIN FOR I FROM 1 TO N DO REPEAT  IF (V==1) THEN C:=2; BREAK; END;  IF (V==2) THEN C:=3; BREAK; END;  IF (V==3) THEN C:=5; BREAK; END;  IF (V==4) THEN C:=7; BREAK; END;  C:=0; // DEFAULT UNTIL 1; // REPEAT...ALWAYS END; // FOR END; // BEGIN EXPORT T2(V,N) // Using CASE statement BEGIN FOR I FROM 1 TO N DO CASE  IF (V==1) THEN C:=2; END;  IF (V==2) THEN C:=3; END;  IF (V==3) THEN C:=5; END;  IF (V==4) THEN C:=7; END; DEFAULT:  C:=0; END; // CASE END; // FOR END; // BEGIN EXPORT TEST(V,N) // Timing CASE Vs Alternative BEGIN LOCAL A,B; A:=TEVAL( T1(V,N) ); // TEVAL B:=TEVAL( T2(V,N) ); RETURN {A,B,C}; END; // BEGIN

The results are:
TEST(1,1) gives {0_s,0.001_s,2}
This indicates the CASE alternative is faster on a single run, but...
TEST(1,1000) gives {0.086_s,0.069_s,2}
This indicates that with a loop of 1000 times, the CASE statement is faster????

In general, TEST(n,1000) indicates that the CASE statement is faster, even for when the DEFAULT is used.

I notice that TEVAL can give different values on successive runs. Why is that?

Also, why would the CASE alternative seem to give a faster run time than CASE for a run of 1, but as soon as N (the loop count) rises, typically with a value of 2, the CASE statement is faster????

Thanks
-Donald
 « Next Oldest | Next Newest »

 Messages In This Thread an HP question... - webmasterpdx - 10-23-2017, 03:57 AM RE: an HP question... - Arno K - 10-23-2017, 06:35 AM RE: an HP question... - webmasterpdx - 10-23-2017, 07:13 AM RE: an HP question... - Didier Lachieze - 10-23-2017, 07:44 AM RE: an HP question... - Arno K - 10-23-2017, 07:37 AM RE: an HP question... - webmasterpdx - 10-23-2017, 08:06 AM RE: an HP question... - Gilles59 - 10-23-2017, 12:16 PM RE: an HP question... - Eddie W. Shore - 10-23-2017, 12:36 PM RE: an HP question... - cyrille de brĂ©bisson - 10-23-2017, 01:39 PM RE: an HP question... - webmasterpdx - 10-23-2017, 10:26 PM RE: an HP question... - webmasterpdx - 10-24-2017 12:58 AM RE: an HP question... - webmasterpdx - 10-24-2017, 01:12 AM RE: an HP question... - webmasterpdx - 10-24-2017, 01:20 AM RE: an HP question... - webmasterpdx - 10-24-2017, 01:38 AM RE: an HP question... - webmasterpdx - 10-24-2017, 02:09 AM RE: an HP question... - webmasterpdx - 10-24-2017, 02:16 AM RE: an HP question... - Joe Horn - 10-24-2017, 06:21 AM RE: an HP question... - cyrille de brĂ©bisson - 10-24-2017, 06:01 AM

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