Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can this code be faster?
Message
From
27/10/2003 09:56:49
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
27/10/2003 09:36:46
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00842920
Message ID:
00842935
Views:
16
>I am pulling information from a file that can be of any size. We have not determined the average size of the file yet. The file starts out with a header and immediately following the header is the size of the data that belongs to that header. For instance in the first line below the header would be 1MHG and the next 167 characters hold data for that header. Starting at position 168 will be 2TRG, position 173 following that will be 6CVA... in the example below:
>
>1MHG167...
>2TRG172...
>6CVA273...
>5VEH272...
>2TRG172...
>6CVA273...
>5VEH272...
>3MTG102...
>
>1MHG is a message header. It occurs only once per message and is the first characters of the string always. 2TRG starts a new transaction. There are many transactions per file.
>
>The speed seems ok at this point, however, the files that I am reading in could get extremely large. Is there any way to speed up the process of the FREAD()? Right now I am processing data a transaction at a time. The file could contain 10,000 or more transactions. It works great functional wise (I'm verifying that I am reading all data in the file), but I want to be prepared in case the file gets much larger and optimize it for speed.
>
>TIA,
>
>Simplified snippet:
>
>
>m.handle =  FOPEN(al3_file)
>m.sizeof = FSEEK(m.handle,0,2)
>=FSEEK(m.handle,0)
>
>DO WHILE !FEOF(m.handle)
>   m.header=FREAD(m.handle,4)
>   m.size = FREAD(m.handle,3)
>   m.data = FREAD(m.handle,VAL(m.size)-7)
>   m.data = CHRTRAN(m.data,'?',' ')
>   DO CASE
>     CASE m.header = '1MHG'		&& beginning of message
>	DO p_1MHG WITH m.header+m.size+m.data
>     CASE m.header = '2TRG'		&& new transaction
>	DO p_2TRG WITH m.header+m.size+m.data
>     CASE m.header = 'Something else'   && about 15-20 cases
>        * etc...
>     CASE m.header = '3MTG'             && end of message
>        * do something
>   ENDCASE
>ENDDO
>=FCLOSE(m.handle)
>
Tracy,
I think it'd be fast.
2 things confused me :
1) Why do you get file size (if not for something used later in snipped code)
2) m.data = FREAD(m.handle,VAL(m.size)-7)
Why -7 ? Wouldn't you be reading next 167 bytes ? Or is it 167 bytes including m.header+m.size?

Using do case instead of if..endif would slow down a bit but might be ignorable.

DO ('p_'+m.Header) WITH m.header+m.size+m.data

might be ?

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform