"Which would you suppose is much faster:"

I think we need to consider that Unibasic in U2 is interpreted (not compiled
into an executable). The "compiled basic" is actually run by the u2 runtime
engine - eg "udt" (for unidata) The code in 1: (see below) does a SELECT
with a condition 'TYPE = "V"'. The U2 engine only has to interpret this line
once. To bring back the required records the U2 engine does not need to
evaluate any more basic code. Whereas in the 2: the "IF REC[1,1]='V' THEN"
has to be interpreted for every record returned, which is very costly in
CPU.

Additionally the number of records returned by the select in 1: will be less
than 2:, because we only return back records where TYPE = "V". Therefore the
LOOP code executes less times in 1: than in 2:. So in 1: we are actioning
less lines of basic code in the loop, again giving us a time saving. You
will generally get time saving where you action one line of basic code that
does many things than doing the same thing with many lines of basic code.

Of course 1 would run even faster if we put an index on "TYPE". Whereas in
"2" we would get no benefit from an index.

   1: T0=TIME()
      FOR I = 1 TO 100
         EXECUTE 'SELECT VOC WITH TYPE = "V" COUNT.SUP'
         LOOP WHILE READNEXT ID
            NULL ;* GOSUB DO.STUFF
         REPEAT
      NEXT I
      T1 = TIME()
      CRT T1-T0
or

   2: T0 = TIME()
      OPEN 'VOC' TO F ELSE STOP
      FOR I = 1 TO 100
      SELECT F
      LOOP WHILE READNEXT  ID
         READ REC FROM F, ID THEN
            IF REC[1,1]='V' THEN
               NULL ;* GOSUB DO.STUFF
            END
         END
      REPEAT
      T1 = TIME()
      CRT T1-T0
-------
u2-users mailing list
[EMAIL PROTECTED]
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to