From 3401d5eb22f87cc541f520a0b486dbc859ebbf72 Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Thu, 18 Mar 2021 15:12:45 -0400 Subject: [PATCH] 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 Auto-Submit: Herb Derby Reviewed-by: Mike Reed --- bench/ParagraphBench.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bench/ParagraphBench.cpp b/bench/ParagraphBench.cpp index 121e5b23c2..25b8668804 100644 --- a/bench/ParagraphBench.cpp +++ b/bench/ParagraphBench.cpp @@ -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 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 {