forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

File reading from host extremely slow?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
Cugo



Joined: 28 Apr 2008
Posts: 5
Location: Home or equivalent

PostPosted: Mon Jun 16, 2008 8:12 pm    Post subject: File reading from host extremely slow? Reply with quote

Hello.
I have recently been experimenting with files.
I use ps2link on the ps2 side and ps2client on the pc side (linux).
So far I have only been reading files from host:.
When I try to read a file byte by byte with fgetc
and immediately print it out with printf i notice that the characters are incoming about 1 each 0,5 second.
And even if i remove the printf outputing each character as it's read from the file it still takes a couple of seconds to read the file.
And the file is only 33bytes in size.
On the other hand the elf file which is much larger get's loaded almost immediately when I execute it.
Is there a faster way to read files?
Is there any more information I should provide or is this a known issue?

Thanks
_________________
Cugo
Back to top
View user's profile Send private message
jbit
Site Admin


Joined: 28 May 2005
Posts: 293
Location: København, Danmark

PostPosted: Mon Jun 16, 2008 9:06 pm    Post subject: Reply with quote

It sounds like you're reading a byte at a time, don't do this, the overhead is huge... Read everything in as once chunk.
Back to top
View user's profile Send private message Visit poster's website
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Mon Jun 16, 2008 9:12 pm    Post subject: Reply with quote

The problem is that the communication between the PS2 and your PC is taking alot longer than the time just read 1 byte from a file. This is a common problem since commucating over the network (I/O in general) is alot slower than your CPU.

For instance if communication takes C ms (milliseconds) and reading 1 byte from PC HDD takes R ms, if you read B bytes one at a time, the total read time will be: C*R*B ms.

If you instead just read all the B bytes in one go, you get C + (R*B).

As an example: C = 500, R = 1, B = 50.

One byte at a time: 500 * 1 * 50 = 25000 ms
All bytes at once: 500 + 1 * 50 = 550 ms

So basicly when dealing with I/O (like the network) you want to read as much data as possible each time you access it.
_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
Cugo



Joined: 28 Apr 2008
Posts: 5
Location: Home or equivalent

PostPosted: Thu Jun 19, 2008 6:34 am    Post subject: Reply with quote

Reading larger chunks of the file at a time helped.
Thanks
_________________
Cugo
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group