ReadByte/WriteByte incredibly slow

Everything else that doesn't fall into one of the other PB categories.
mp303

ReadByte/WriteByte incredibly slow

Post by mp303 »

"This library use buffered functions to increase the writing/reading speed"

Maybe buffering doesn't work for ReadByte/WriteByte functions? ... I'm doing some file conversion, and relying on what the helpfile said, I figured why do my own buffering? buffering "on top" of routines that are already buffered would just be extra overhead - so I'm reading/writing one byte at a time, like so:

Code: Select all

      While ~Eof(#FileIn)
        UseFile(#FileIn)
        i = ReadByte()
        UseFile(#FileOut)
        WriteByte(i)
      Wend
for a 5 MB file, such a copy operation takes nearly 20 seconds on a 2.5 GHz Pentium 4, which is crazy - if these routines are buffered, surely they don't work as intended.

of course my routines do way more than that, but to see whether the 20 seconds of overhead were coming from the actual work or from reading/writing, I removed all the code ... the actual work doesn't make up for even 1% of the CPU usage! 8O ... in other words, if not for the incredibly slow read/write operations, my program would finish in about 0.2 seconds instead of 20! :?

so now I do have to do my own buffering.

which is incredibly tedious, because I was counting on the library to do what the helpfile promises, and I hate having to reinvent the wheel...

*sigh*
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

and I hate having to reinvent the wheel...
So don't reinvent the wheel, use the FastFile ASM library written by Rings :)
Image Image
Gantry
User
User
Posts: 20
Joined: Tue Jun 03, 2003 6:24 am
Location: Sweden

Post by Gantry »

I have had the same experience. While it is a good thing not having to reinvent the wheel, I still wonder why we should have to use someone elses wheels. Any plans for rewriting the file routines included in PB?

Still, having completed my first major project in PB I can only say that I love it. My previous releases of the same program had been coded first in c++ builder and then delphi. I rewrote the program in PB. It took me less time to code and the executable was 21 kB instead of 250 kB and with added functionality too. :P

Regards,

Gantry
*** In the end we will remember not the words of our enemies, but the silence of our friends. (Martin Luther King Jr.) ***
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Yes, I plan to redo these routines.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

The use of the Fastfile - Lib is free, for everyone using a legal copy of Purebasic .
Of Course the lib is Windows-based only, so a native implement in Purebasic is not so easy and i haven't enough expierence under Linux-apis .
I do not want publish the Source of the library to the public, but i'm open to discuss that later with Fred personally ;)
SPAMINATOR NR.1
matthew180
User
User
Posts: 64
Joined: Mon Jun 30, 2003 5:36 pm
Location: Michigan
Contact:

Post by matthew180 »

Fred wrote:Yes, I plan to redo these routines.
When? Can anyone help?

mp303 wrote:so now I do have to do my own buffering.
I already had a run in with the file functions and wrote a buffered version of ReadString(). My code could be easily modified to work like ReadByte() if you don't want to spend time coding your own buffered read functions.

Matthew
mp303

Post by mp303 »

thanks, but I need both read and wrtite functions... besides, this can't (shouldn't) be implemented as functions - the buffers should be integrated into the reading/writing code itself, otherwise I still have four function calls for ever processed byte, which is way too much...
matthew180
User
User
Posts: 64
Joined: Mon Jun 30, 2003 5:36 pm
Location: Michigan
Contact:

Post by matthew180 »

Well, if you need a work around right now, I guess you don't have many choices, unless you think you can wait for Fred to rewrite the functions... But I would not hold my breath on that.

My function uses ReadData() and a 64K buffer, so the amount of system IO is minimal, and the data can be treated however you like. I don't have a write function, but it would be trivial compared to the read function. Actaully, now that I think about it, a byte read would be pretty eacy too, compared to reading one line at a time (since I had to look for end-of-line and all that crap.)

Matthew
mp303

Post by mp303 »

Matt,

On second thought, I'd like to take a look at your code, is it online anywhere?

Rings,

I checked out your FastFile library ... buuuuut, uhm ... is it a beta/prototype, or did you just not think anyone would need to open more than one file at a time? 8O
matthew180
User
User
Posts: 64
Joined: Mon Jun 30, 2003 5:36 pm
Location: Michigan
Contact:

Post by matthew180 »

Okay, let me detangle it from the project I wrote it for and I'll send it your way.

Matthew
matthew180
User
User
Posts: 64
Joined: Mon Jun 30, 2003 5:36 pm
Location: Michigan
Contact:

Post by matthew180 »

Okay, I've got some functions for you, but I have to sleep... I'll put them up tomorrow (I'm in GMT -5). I added a single byte read and write for you to use, as well as cleaned up the readstring function.

Matthew
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

mp303 wrote:Rings,
I checked out your FastFile library ... buuuuut, uhm ... is it a beta/prototype, or did you just not think anyone would need to open more than one file at a time? 8O
No, no beta or Prototype, just a first version that works.
You can use 2 Files if you tackle the second file with the 'B' Functions.
For example FastOpenFileB, FastReadByteB etc...
That is of course only a workaround, but i will not loos speed whicle switching between files.
For a next version there is be planned to use a Filepointer like
FastOpenFile(Filenumber,Filename) or FastReadByte(FileNumber,Offset)
and other goodies like FastCrypting .... .
Well, let me see what holidays offer free time for coding..
SPAMINATOR NR.1
matthew180
User
User
Posts: 64
Joined: Mon Jun 30, 2003 5:36 pm
Location: Michigan
Contact:

Post by matthew180 »

My file code is up:

http://www.purebasic.org

Hit the Article link to FishLib. Let me know if you have any questions.

Matthew
Post Reply