QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: TheGuardHQ on December 03, 2018, 09:02:55 am

Title: File Read slow
Post by: TheGuardHQ on December 03, 2018, 09:02:55 am
Hello everybody.

I have a question about the following sample code:

OPEN "c:\temp\kdb053.txt" FOR INPUT AS #1
t# = TIMER
WHILE NOT EOF(1)
    LINE INPUT #1, zeile$
WEND
PRINT TIMER - t#
CLOSE


The file "kdb053.txt" has about 100,000 lines.
When I start the program with QuickBasic 7.1, it takes 0.2 seconds.
QB64 takes over 16 seconds for the same program!

Does anyone have any idea where the problem is?

Thanks and good greeting
Christian
Title: Re: File Read slow
Post by: FellippeHeitor on December 03, 2018, 09:27:28 am
Open for BINARY access. That's a QB64 feature (in INPUT mode it is slow to maintain legacy behavior of reading the disk a certain way).

Code: QB64: [Select]
  1. OPEN "c:\temp\kdb053.txt" FOR BINARY AS #1
  2. t# = TIMER
  3.     LINE INPUT #1, zeile$

BTW, welcome to the forum!
Title: Re: File Read slow
Post by: TheGuardHQ on December 03, 2018, 09:50:49 am
Hi FellippeHeitor,

that really helped me a lot - THANKS!

The program now processes the 100,000 lines in 0.49 seconds.
That sounds good at first, but QB71 is still more than twice as fast.

In this small sample program that does not matter. But if I have to read a lot of files very often, you still notice the difference clearly.

Is there still a way to make it faster or is not there any more?

Christian
Title: Re: File Read slow
Post by: FellippeHeitor on December 03, 2018, 10:04:45 am
You could read the whole file at once:

Code: QB64: [Select]
  1. OPEN "c:\temp\kdb053.txt" FOR BINARY AS #1
  2. t# = TIMER
  3. zeile$ = SPACE$(LOF(1))
  4. GET #1, 1, zeile$

But then you'll have to parse it manually for line breaks.
Title: Re: File Read slow
Post by: TheGuardHQ on December 03, 2018, 10:05:24 am
Many Thanks!
Title: Re: File Read slow
Post by: Pete on December 03, 2018, 11:49:42 am
Now I'm curious as to how your old app was twice as fast as QB64 binary reads. How did you read the file in PDS (QB 7.1)? I never tried it, I bought a copy of QuickBASIC (QB45) in 1990 and it was all I needed until QB64 came along.

Pete