Skip to content

Add tests and benchmarks for BitReader, speedup ~10 times

Stefan Brüns requested to merge work/bruns/bitreader_cleanup into master

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.

  1. Replace the padding by explicit handling of read()s at the end of the data.
  2. Make sure the data is not detached for reading.
  3. Keep already read data
  4. 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

Merge request reports

Loading