improve SkParagraph's bench accuracy

Call onDraw in onDelayedSetup to warm up the glyph cache
otherwise nanobench will mis-caclulate the loop count.

This change also reduces the variability of the benchmark.

Change-Id: I5f3f2167cc78b996fcb589644b70622d18af240b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/386816
Commit-Queue: Mike Reed <reed@google.com>
Auto-Submit: Herb Derby <herb@google.com>
Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
Herb Derby 2021-03-18 15:12:45 -04:00 committed by Skia Commit-Bot
parent 049f0dfaba
commit 3401d5eb22

View File

@ -16,7 +16,7 @@
#include "modules/skparagraph/include/ParagraphBuilder.h"
#include "modules/skparagraph/include/ParagraphStyle.h"
class ParagraphBench : public Benchmark {
class ParagraphBench final : public Benchmark {
SkString fName;
sk_sp<skia::textlayout::FontCollection> fFontCollection;
skia::textlayout::TextStyle fTStyle;
@ -73,6 +73,11 @@ protected:
builder->addText(text);
builder->pop();
fParagraph = builder->Build();
// Call onDraw once to warm up the glyph cache otherwise nanobench will mis-calculate the
// loop count.
SkCanvas canvas;
this->onDraw(1, &canvas);
}
void onDraw(int loops, SkCanvas* canvas) override {