David J Murray
~ Learn and Do - Excel and Share ~

Timing TRANS and READ

Jan 25, 2006

Image by Chaos07 from Pixabay

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 RAISE 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.

About the Author

<a href="https://davidjmurray.org/author/davidjmurray/" target="_self">djm</a>

djm

I have been in the computer/IT industry for over 35 years. After spending half a life-time in highly proprietary database environments, I have succumbed to the WordPress Eco-system and I'm well down the chasm. I am specializing in AWS hosting, Wordpress CMS, Elegant Themes, in particular Divi and Extra themes.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This