Add skottie-vs-png decode bench

Three flavors:

  - png data  -> bitmap
  - json data -> skottie::Animation -> SkPicture
  - json data -> skottie::Animation

    micros   	bench
     70.20  	decode_png_small	nonrendering
      4.32 ?	decode_skottiepic_small	nonrendering
      3.71 ?	decode_skottie_small	nonrendering

   4589.10  	decode_png_medium	nonrendering
    117.48 ?	decode_skottiepic_medium	nonrendering
     76.69 ?	decode_skottie_medium	nonrendering

  30895.97  	decode_png_large	nonrendering
   4911.16  	decode_skottiepic_large	nonrendering
   4640.39  	decode_skottie_large	nonrendering

Change-Id: Id93be15f453b70e8cb51ea38f33adc1ebc9ce562
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/423819
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
This commit is contained in:
Florin Malita 2021-07-01 10:29:26 -04:00 committed by Skia Commit-Bot
parent 4d45e09202
commit d584ddd151
2 changed files with 114 additions and 0 deletions

113
bench/DecodeBench.cpp Normal file
View File

@ -0,0 +1,113 @@
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "bench/Benchmark.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkPictureRecorder.h"
#include "modules/skottie/include/Skottie.h"
#include "tools/Resources.h"
class DecodeBench : public Benchmark {
protected:
DecodeBench(const char* name, const char* source)
: fName(SkStringPrintf("decode_%s", name))
, fSource(source)
{}
bool isSuitableFor(Backend backend) final {
return backend == kNonRendering_Backend;
}
const char* onGetName() final { return fName.c_str(); }
void onDelayedSetup() override {
fData = GetResourceAsData(fSource);
SkASSERT(fData);
}
protected:
sk_sp<SkData> fData;
private:
const SkString fName;
const char* fSource;
};
class BitmapDecodeBench final : public DecodeBench {
public:
BitmapDecodeBench(const char* name, const char* source)
: INHERITED(name, source)
{}
void onDraw(int loops, SkCanvas*) override {
while (loops-- > 0) {
SkBitmap bm;
SkAssertResult(DecodeDataToBitmap(fData, &bm));
}
}
private:
using INHERITED = DecodeBench;
};
class SkottieDecodeBench final : public DecodeBench {
public:
SkottieDecodeBench(const char* name, const char* source)
: INHERITED(name, source)
{}
void onDraw(int loops, SkCanvas*) override {
while (loops-- > 0) {
const auto anim = skottie::Animation::Make(reinterpret_cast<const char*>(fData->data()),
fData->size());
}
}
private:
using INHERITED = DecodeBench;
};
class SkottiePictureDecodeBench final : public DecodeBench {
public:
SkottiePictureDecodeBench(const char* name, const char* source)
: INHERITED(name, source)
{}
void onDraw(int loops, SkCanvas*) override {
while (loops-- > 0) {
const auto anim = skottie::Animation::Make(reinterpret_cast<const char*>(fData->data()),
fData->size());
SkPictureRecorder recorder;
anim->seek(0);
anim->render(recorder.beginRecording(anim->size().width(), anim->size().height()));
const auto pic = recorder.finishRecordingAsPicture();
}
}
private:
using INHERITED = DecodeBench;
};
DEF_BENCH(return new SkottieDecodeBench("skottie_large", // 426593
"skottie/skottie-text-scale-to-fit-minmax.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_medium", // 10947
"skottie/skottie-sphere-effect.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_small", // 1112
"skottie/skottie_sample_multiframe.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_large",
"skottie/skottie-text-scale-to-fit-minmax.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_medium",
"skottie/skottie-sphere-effect.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_small",
"skottie/skottie_sample_multiframe.json"));
DEF_BENCH(return new BitmapDecodeBench("png_large" , "images/img_0.png")); // 2000x1047
DEF_BENCH(return new BitmapDecodeBench("png_medium", "images/mandrill_512.png")); // 512x 512
DEF_BENCH(return new BitmapDecodeBench("png_small" , "images/mandrill_32.png")); // 32x 32

View File

@ -38,6 +38,7 @@ bench_sources = [
"$_bench/CubicMapBench.cpp",
"$_bench/DDLRecorderBench.cpp",
"$_bench/DashBench.cpp",
"$_bench/DecodeBench.cpp",
"$_bench/DisplacementBench.cpp",
"$_bench/DrawBitmapAABench.cpp",
"$_bench/EncodeBench.cpp",