Improve performance of createOrderedModel using QVector
This change improves the performance of GuessLanguagePrivate::createOrderedModel()
by about 2x. The performance improvement comes from:
- Using QVector to just store the data initially
- Sorting with std::sort instead of with QMultiMap
The performance of spellchecker with language auto-detection will directly benefit from this change. Some data:
Before
RESULT : SonnetAutoDetectTest::performanceBefore():"English":
0.00787 msecs per iteration (total: 788, iterations: 100000)
PASS : SonnetAutoDetectTest::performanceBefore(German)
RESULT : SonnetAutoDetectTest::performanceBefore():"German":
0.00779 msecs per iteration (total: 779, iterations: 100000)
PASS : SonnetAutoDetectTest::performanceBefore(Malayam)
RESULT : SonnetAutoDetectTest::performanceBefore():"Malayam":
0.01904 msecs per iteration (total: 1,904, iterations: 100000)
PASS : SonnetAutoDetectTest::performanceBefore(Urdu)
RESULT : SonnetAutoDetectTest::performanceBefore():"Urdu":
0.01192 msecs per iteration (total: 1,193, iterations: 100000)
QWARN : SonnetAutoDetectTest::performanceAfter()
After
PASS : SonnetAutoDetectTest::performanceAfter(English)
RESULT : SonnetAutoDetectTest::performanceAfter():"English":
0.00500 msecs per iteration (total: 500, iterations: 100000)
PASS : SonnetAutoDetectTest::performanceAfter(German)
RESULT : SonnetAutoDetectTest::performanceAfter():"German":
0.00496 msecs per iteration (total: 497, iterations: 100000)
PASS : SonnetAutoDetectTest::performanceAfter(Malayam)
RESULT : SonnetAutoDetectTest::performanceAfter():"Malayam":
0.01204 msecs per iteration (total: 1,205, iterations: 100000)
PASS : SonnetAutoDetectTest::performanceAfter(Urdu)
RESULT : SonnetAutoDetectTest::performanceAfter():"Urdu":
0.00753 msecs per iteration (total: 754, iterations: 100000)
The benchmark for measuring exactly this function is hard and needs unnecessary API modifications and as such, I will remove the benchmark once this is ready to be merged. We can write a benchmark measuring the "whole" guess language thing but the results for that vary a lot depending upon how you have setup your dictionaries so that isn't very beneficial in measuring this change.
Edited by Albert Astals Cid