Fastest way to process a file

I'm using Dev-Cpp 4.9.9.2

I want to encrypt a file.
Every byte has to be encrypted on its own.
Is it faster to?

A
1. read a single byte
2. encrypt a single byte
3. write a single byte

B
1. Load the whole file to a string
2. Encrypt the string
3. Write the encrypted string to a file

So is it faster to load the file to a string or use the file functions directly?
I will use if- and ofstream objects.
Less system calls is probably slightly better, though you probably won't see a measurable performance gain unless the file is big, in which case it might not be practical to read the entire file at once.

If performance is absolutely critical, I usually read blocks of 64K or multiples thereof, because I know that my OS reads data from the hard disk in 64K blocks (even if you request only a single byte be read).
Topic archived. No new replies allowed.