Author Topic: File Read slow  (Read 3496 times)

0 Members and 1 Guest are viewing this topic.

Offline TheGuardHQ

  • Newbie
  • Posts: 6
    • View Profile
File Read slow
« 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

FellippeHeitor

  • Guest
Re: File Read slow
« Reply #1 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!
« Last Edit: December 03, 2018, 09:42:56 am by FellippeHeitor »

Offline TheGuardHQ

  • Newbie
  • Posts: 6
    • View Profile
Re: File Read slow
« Reply #2 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

FellippeHeitor

  • Guest
Re: File Read slow
« Reply #3 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.

Offline TheGuardHQ

  • Newbie
  • Posts: 6
    • View Profile
Re: File Read slow
« Reply #4 on: December 03, 2018, 10:05:24 am »
Many Thanks!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: File Read slow
« Reply #5 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/