This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need to speed this algorithm up  RSS feed

 
Jeremy Tartaglia
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a very simple game engine, and I'm running into a peformance issue. I need to load a specific "unknown" file format, but the way I'm doing it is excrutiatingly slow (1-2.5 seconds for a 640x480 image). My loading code is posted below, as well as the functions used. I just don't know enough about loading files/decompression to make this much faster. Any help would be appreciated. Thanks!

readByte, readWord, readDWord, and readColor are all static method of another class called "LittleEndianFile", which reads in little endian values. readColor reads in a BGR value into RGB in a single integer value. All of these use bit shifts for speed. Only readDWord is listed.


[ January 29, 2006: Message edited by: Jeremy Tartaglia ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, one very easy thing to try is to use buffered IO:

InputStream file=new BufferedInputStream(new FileInputStream(name));

The rest of the program remains the same (assuming readByte(), etc, all accept InputStream as an argument type; as a general rule, that would be the more appropriate way to write them anyway.) You should see at least a small improvement, and potentially much more, by doing this.
 
Jeremy Tartaglia
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, that's a huge improvement. I don't think I need more performance than that.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... You're welcome!
 
Jeremy Tartaglia
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, thanks again. Sorry, thought I said that before.

It's amazing. I have six books on Java (three on game development alone) and not one of them mentioned BufferedInputStream. Only FileInputStream, and some other Reader classes. It's almost as if they expect you to use well documented, natively incorporated files.

Thanks again.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Out of curiosity how much of a performance difference did the buffered IO make?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!