Add tests and benchmarks for BitReader, speedup ~10 times
The BitReader recurrently detaches the used QByteArray:
- during initialization to add padding
- during read() calls due to non-const operator[] calls
This is exaggerated as each read() fetches the same data repeatedly, causing 4 to 5 detaches each time.
- Replace the padding by explicit handling of read()s at the end of the data.
- Make sure the data is not detached for reading.
- Keep already read data
- Read 4 bytes at once if possible
Benchmark results for old vs new code:
RESULT : BitReaderTest::benchmarkInit():
0.000099 msecs per iteration (total: 52, iterations: 524288)
RESULT : BitReaderTest::benchmarkInitSlice():
0.00016 msecs per iteration (total: 85, iterations: 524288)
RESULT : BitReaderTest::benchmarkRead1Bit():
0.087 msecs per iteration (total: 90, iterations: 1024)
RESULT : BitReaderTest::benchmarkRead8Bit():
0.072 msecs per iteration (total: 74, iterations: 1024)
RESULT : BitReaderTest::benchmarkInit():
0.000025 msecs per iteration (total: 53, iterations: 2097152)
RESULT : BitReaderTest::benchmarkInitSlice():
0.000079 msecs per iteration (total: 83, iterations: 1048576)
RESULT : BitReaderTest::benchmarkRead1Bit():
0.0060 msecs per iteration (total: 99, iterations: 16384)
RESULT : BitReaderTest::benchmarkRead8Bit():
0.0086 msecs per iteration (total: 71, iterations: 8192)
Edited by Stefan Brüns