Click to See Complete Forum and Search --> : Speed up reading


Cakkie
August 30th, 2001, 01:06 AM
I have this program that does some encoding. The program needs about 20 seconds to encode a file about 8 megs.
Of those 20 seconds, it takes about 3 seconds to encode the file. The remaining time is used by the reading of the file.
What I was wondering is that if there is a faster way to read the data. I'm reading the data into a string, that I then convert to a bytearray.
This is the code I use to do that

Open "somefile" for binary access read as #ffile
strInput = input(FileLen("somefile"),#ffile)
arrInput = StrConv(strInput,vbFromUnicode)




Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

shree
August 30th, 2001, 09:58 AM
Will reading directly into a byte array make it faster?

Dim FileAsByte() as Byte
FileHandle = FreeFile
Open sFileName for binary as FileHandle
ReDim FileAsByte(LOF(FileHandle))
get FileHandle, , FileAsByte

Cakkie
August 30th, 2001, 10:23 AM
Man, I didn't know Get was that much faster as Input. It takes about 200 ms to read the entire file (about 2.5 megs) into memory. I guess it is because i'm not going via strings any more. I tried doing it with input, reading the entire file into a byte array, but the problem there was that it was reading Unicode, giving me an array twice as big, with an empty (Null) byte after each other one. Even then it was slow like hell.


Thanx a lot!

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

Cimperiali
August 31st, 2001, 01:53 AM
Too bad I already finished my votes...

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater

Cimperiali
August 31st, 2001, 01:55 AM
I found out conversion operations (from byte to String and so on) and string manipulations (using Mid$, Left$, Right$,...) slow down a lot.

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater