Faster file handling

Just starting out? Need help? Post your questions and find answers here.
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Faster file handling

Post by Tipperton »

I re-wrote a program I had originally written in PowerBasic into PureBasic because I wanted to give it a GUI to make it easier to use. PowerBasic's DDT system is overly complex compared to PureBasic's Gadget system.

End result: The PowerBasic program finished the file in less time than it took the PureBasic program to do one percent of the file!

So I know file operations (specifically string reading and writing) can be a lot faster.
Last edited by Tipperton on Sat Aug 05, 2006 8:56 pm, edited 1 time in total.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

Did you try ' FileBuffersSize(#File, size) ' :?: :?:
Last edited by Flype on Sat Aug 05, 2006 1:03 pm, edited 2 times in total.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post by inc. »

Also a piece of you code would be nice to see your approach.

And bigger files always should be handled blockwise - if not done already.
Check out OOP support for PB here!
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post by Tipperton »

Code: Select all

ReadFile(0, "filein.txt")
CreateFile(1, "fileout.txt")
Repeat
  sInputLine=ReadString(0)
  <process record>
  WriteStringN(1, sOutputLine)
Until Eof(0)
CloseFile(0)
CloseFile(1)
My point is based on other languages, PowerBasic, and Visual Basic, both of which can process the file in this fashion much faster than PureBasic does, that faster reading and writing of files is possible and shouldn't require extra libraries or special coding.

I had ran into this before (as did other PureBasic users) and switched to PowerBasic. The problem with PowerBasic is that it assumes you know and understand Windows API programming because that's all their DDT (Dynamic Dialog Tools) system is is just built in commands that mirror the API. When I discovered that PureBasic had released version 4 I decided to try it. It's nice but it appears the file reading and writting is still as slow as it was before.

So I decided to add improved file reading and writing to the wish list/feature requests.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

Is FileBuffersSize(#File, size) really hard to use ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post by Tipperton »

Flype wrote:Is FileBuffersSize(#File, size) really hard to use ?
Tried it, increasing the buffer size from the default 4096 to 65536.

Considering the records average about 300 bytes each, it made little (if any) difference.

BTW: I saw references to Rings' FastFile library but it doesn't appear to be on any of the PureBasic support sites like PureProject or PureArea. Is it no longer available?
Fred
Administrator
Administrator
Posts: 18409
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

It's definitely much faster than before, and to me it sounds quite hard to reduce a lot the string reading speed anymore. Can you put the PowerBasic and VB executable + code available so i could test ? I assume you disabled the debugger as well.
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

My tip is an enabled debugger as well^^
PB Is deffinitely very fast when it comes to file access, don't think VB can beat that, especially their .Net versions
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Tipperton wrote:

Code: Select all

<process record>
Maybe this is actually the cause of the delay, rather than the disk read/write?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post by Tipperton »

Yes, the debugger is disabled.
PB wrote:
Tipperton wrote:

Code: Select all

<process record>
Maybe this is actually the cause of the delay, rather than the disk read/write?
Possibly, I've seen comments that PureBasic's string handling isn't all that fast though I'm not really doing anything all that fancy.

The file is in comma separated fields and all I'm doing is combining a couple of the fields into one field, formatting a couple of others, and deleting a few others. Then writing the result to an output file.
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post by Tipperton »

Continued in this thread:

http://www.purebasic.fr/english/viewtopic.php?p=155678

Because this is becomming more of a discussion rather than an enhancement request.
Fred
Administrator
Administrator
Posts: 18409
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Tipperton wrote:Possibly, I've seen comments that PureBasic's string handling isn't all that fast though I'm not really doing anything all that fancy.
Please stop doing such assumptions, as you seem to not be very experienced with PB (strings handling in PB is very fast). We can move a topic when it's needed, so no need to create a second one (for the next time).
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post by Tipperton »

Fred wrote:Please stop doing such assumptions, as you seem to not be very experienced with PB (strings handling in PB is very fast).
What assumptions? I've seen a number of posts that say that even in v4 that string functions aren't as fast as they could be. I'm just quoting those posts. I figure they have more PureBasic experience than I do so they must know something that I don't.
Fred wrote:We can move a topic when it's needed, so no need to create a second one (for the next time).
Noted: If this forum software is anything like what I use for the forum I run, you should be able to move this topic and merge it with the other if you wish.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

show code... please?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post by Tipperton »

blueznl wrote:show code... please?
The code is in this thread: http://www.purebasic.fr/english/viewtopic.php?p=155678

The problem has been solved, it turned out to be how often I was calling a function that allowed Windows to process events in general.

Thanks anyway.
Post Reply