What is the difference between a TRANS() statement and a READ statement time wise? Why bother to find out?

I use a lot of small subroutines to calculate business rules. These routines can be used in derived fields and in further routines – in Unibasic subroutines and programs or as a SB+ process.

Therefore, the speed of different methods becomes relevant.

As I use SB+, I have access to a routine called SB.FILEVAR.S which caches file opens.

For reading from a file, you can use either the TRANS or READ statements. The difference is that the READ requires an OPEN before the READ whereas the TRANS requires a RIASE to place the record in the same format as the READ.

Using a file of almost 112,000 records, using UniVerse 10.1.18 on MS-Windows 2000 Server, the results are as follows:

Using an OPEN and READ:

OPEN "FILE" TO FILE.FV ELSE STOP
READ FILE.REC FROM FILE.FV, FILE.ID ELSE FILE.REC = EMPTY.STR
  • 1 record – 14:09 minutes
  • 2 fields – 14:15 minutes
  • 3 fields – 14:20 minutes

Using an SB.FILEVAR.S and READ:

CALL SB.FILEVAR.S("FILE", 0, FILE.FV, ERR)
READ FILE.REC FROM FILE.FV, FILE.ID ELSE FILE.REC = EMPTY.STR
  • 1 record – 5 seconds
  • 2 fields – 8 seconds
  • 3 fields – 11 seconds

Using an TRANS and RAISE:

FILE.REC = RAISE(TRANS("FILE", FILE.ID, -1, "X"))
  • 1 record – 4 seconds
  • 2 fields – 7 seconds
  • 3 fields – 11 seconds

The difference between the cached file open and the TRANS is insignificant really (within the scope of this testing process). The big difference is the OPEN statement – very slow.

Therefore, when writing small routines to read a record or field and calculate a single returned answer which you wish to use in a derived field or as a function – use TRANS.