I can't imagine that a 12% speed difference matters that much to you. We're in Java, so we've already decided that speed is not important, at least not percentage differences. Time complexity of algorithms, yes, but a factor of 12% is not important. I'm surprised, however, that readBits() runs as fast as it does - I'd think readByte() would be many times faster.
Anyway, think, for a minute, about if you actually wanted to get signed bytes from a file. So if readByte() returned something unsigned, you'd have to correct it. It's just two sides of the same coin: which interface do you want? Obviously, you'd rather it return an unsigned value. I however, think readBits() is more than enough, especially given that you could optimize for this case (read 8 aligned bits in) if you really wanted. Also, since Byte/byte in Java is a signed value, you'd think that readByte() would return a byte with a signed value. It's all a matter of personal opinion, however. |