Vroom
Published By | Date | Version | Knowledge Level | Keywords |
---|---|---|---|---|
Sprezzatura Ltd | 01 APR 1990 | 1.16+ | EXPERT | VROOM, INDEX, SELECT, BASIC, PERFORM, SPEED, FIELD |
As promised, the first in an occasional series with hints on getting the most from Advanced Revelation. Whilst it is generally more cost effective to put in faster hardware than spend weeks optimising software, an awareness of possible improvements is still useful. Some of the hints included here may seem obvious, but all are taken from hints delivered to experienced REV/AREV programmers recently.
Testing For a Value
It is frequently necessary when eliciting user response to ensure that the information returned is valid. This can be done in the following manner (the code is by way of example only, obviously it can be improved in other ways, popups, collectors, @LOWER.CASE etc).
VALID = 0 ANS = "" LOOP CALL MSG("Y/N","RC",ANS,"") IF ANS="Y" OR ANS="y" OR ANS="N" OR ANS="n" THEN VALID = 1 END UNTIL VALID REPEAT
however, it can be accomplished more efficiently with the construct
VALID = 0 ANS = "" LOOP CALL MSG("Y/N","R",ANS,"") IF INDEX("YyNn",ANS,1) THEN VALID = 1 UNTIL VALID REPEAT
This construct also has the advantage that its performance hardly degrades as the amount of comparisons increase unlike the former method. In the table below, the same comparisons were performed multiple times to evaluate the times taken for each. From this it can be seen that INDEX is quicker even if testing for a single value. (This benchmark was performed on 2.0)
Comparisons ³ 1 ³ 2 ³ 3 ³ 4 ³ 10 ÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄ INDEX ³ 2.03 ³ 2.08 ³ 2.09 ³ 2.11 ³ 2.36 IF n OR n ³ 2.25 ³ 3.35 ³ 4.45 ³ 5.60 ³ 12.14
Extracting Parts of Keys
When dealing with a two part key (or similar) it is quicker to use the FIELD function (EG PART1 = FIELD(KEY,"*",1)) than to use the [ ] syntax (EG PART1 = KEY[1,"*"]).
Selecting Records From File
When selecting records from file for subsequent processing AND THE FIELDS FORMING THE SELECTION CRITERIA ARE NOT INDEXED it is quicker to extract the required records by reading in all records and doing the required comparison in BASIC than by PERFORMing a select. I have seen the latter done at several sites visited lately and speed improvements of upto 100% have been gained by adopting the former method (depending on the complexity of he comparison criteria).
(Volume 1, Issue 10, Pages 8,9)