Add benchmark for KTextToHTML::convertToHtml

Review Request #129859 - Created Jan. 20, 2017 and submitted

Information
Milian Wolff
kcoreaddons
master
f76c35d...
Reviewers
kdeframeworks
dfaure, dvratil, mlaurent
On my machine, the initial output is as follows for RelWithDebInfo:

PASS   : KTextToHTMLTest::benchHtmlConvert(plain)
RESULT : KTextToHTMLTest::benchHtmlConvert():"plain":
     4.0 msecs per iteration (total: 65, iterations: 16)
PASS   : KTextToHTMLTest::benchHtmlConvert(preserve-spaces)
RESULT : KTextToHTMLTest::benchHtmlConvert():"preserve-spaces":
     3.4 msecs per iteration (total: 55, iterations: 16)
PASS   : KTextToHTMLTest::benchHtmlConvert(highlight-text)
RESULT : KTextToHTMLTest::benchHtmlConvert():"highlight-text":
     4.2 msecs per iteration (total: 68, iterations: 16)
PASS   : KTextToHTMLTest::benchHtmlConvert(replace-smileys)
RESULT : KTextToHTMLTest::benchHtmlConvert():"replace-smileys":
     4.1 msecs per iteration (total: 66, iterations: 16)
PASS   : KTextToHTMLTest::benchHtmlConvert(preserve-spaces+highlight-text)
RESULT : KTextToHTMLTest::benchHtmlConvert():"preserve-spaces+highlight-text":
     3.6 msecs per iteration (total: 58, iterations: 16)
PASS   : KTextToHTMLTest::benchHtmlConvert(preserve-spaces+highlight-text+replace-smileys)
RESULT : KTextToHTMLTest::benchHtmlConvert():"preserve-spaces+highlight-text+replace-smileys":
     3.5 msecs per iteration (total: 57, iterations: 16)

Replace heap-allocated list of chars with QStringLiteral

The main bottleneck in the benchmark for KTextToHTML was actually
constructing the temporary list of word-boundaries. Instead of
doing that all the time, use a QStringLiteral-constructed static
QString.

This improves the benchmarks by more than ~4x on my machine,
all compiled in RelWithDebInfo:

PASS   : KTextToHTMLTest::benchHtmlConvert(plain)
RESULT : KTextToHTMLTest::benchHtmlConvert():"plain":
     0.75 msecs per iteration (total: 96, iterations: 128)
PASS   : KTextToHTMLTest::benchHtmlConvert(preserve-spaces)
RESULT : KTextToHTMLTest::benchHtmlConvert():"preserve-spaces":
     0.71 msecs per iteration (total: 91, iterations: 128)
PASS   : KTextToHTMLTest::benchHtmlConvert(highlight-text)
RESULT : KTextToHTMLTest::benchHtmlConvert():"highlight-text":
     0.89 msecs per iteration (total: 57, iterations: 64)
PASS   : KTextToHTMLTest::benchHtmlConvert(replace-smileys)
RESULT : KTextToHTMLTest::benchHtmlConvert():"replace-smileys":
     0.75 msecs per iteration (total: 96, iterations: 128)
PASS   : KTextToHTMLTest::benchHtmlConvert(preserve-spaces+highlight-text)
RESULT : KTextToHTMLTest::benchHtmlConvert():"preserve-spaces+highlight-text":
     0.79 msecs per iteration (total: 51, iterations: 64)
PASS   : KTextToHTMLTest::benchHtmlConvert(preserve-spaces+highlight-text+replace-smileys)
RESULT : KTextToHTMLTest::benchHtmlConvert():"preserve-spaces+highlight-text+replace-smileys":
     0.79 msecs per iteration (total: 51, iterations: 64)

Remove temporary string allocations

Instead of calling .mid() to compare to a QLatin1String,
call .midRef() as that won't allocate.

Improves the performance of the unit test by ~2x on my
machine when compiling in RelWithDebInfo:

PASS   : KTextToHTMLTest::benchHtmlConvert(plain)
RESULT : KTextToHTMLTest::benchHtmlConvert():"plain":
     0.40 msecs per iteration (total: 52, iterations: 128)
PASS   : KTextToHTMLTest::benchHtmlConvert(preserve-spaces)
RESULT : KTextToHTMLTest::benchHtmlConvert():"preserve-spaces":
     0.36 msecs per iteration (total: 93, iterations: 256)
PASS   : KTextToHTMLTest::benchHtmlConvert(highlight-text)
RESULT : KTextToHTMLTest::benchHtmlConvert():"highlight-text":
     0.51 msecs per iteration (total: 66, iterations: 128)
PASS   : KTextToHTMLTest::benchHtmlConvert(replace-smileys)
RESULT : KTextToHTMLTest::benchHtmlConvert():"replace-smileys":
     0.41 msecs per iteration (total: 53, iterations: 128)
PASS   : KTextToHTMLTest::benchHtmlConvert(preserve-spaces+highlight-text)
RESULT : KTextToHTMLTest::benchHtmlConvert():"preserve-spaces+highlight-text":
     0.44 msecs per iteration (total: 57, iterations: 128)
PASS   : KTextToHTMLTest::benchHtmlConvert(preserve-spaces+highlight-text+replace-smileys)
RESULT : KTextToHTMLTest::benchHtmlConvert():"preserve-spaces+highlight-text+replace-smileys":
     0.46 msecs per iteration (total: 59, iterations: 128)

Mark some methods as const

the test still passes fine. note that the above is actually split into 4 commits locally

David Faure
Milian Wolff
Review request changed

Status: Closed (submitted)

Loading...