skia2/bench/WritePixelsBench.cpp
Mike Reed af990f3bb9 update/add benches to look at colorspace as well as alphatype
Example run:

  24/24  MB	14	332µs	338µs	337µs	341µs	gl	readpix_um_bgra_srgb
  24/24  MB	9	568µs	581µs	581µs	595µs	glsrgb	readpix_um_bgra_srgb
  29/29  MB	10	334µs	340µs	340µs	351µs	gl	readpix_um_bgra_null
  28/29  MB	8	553µs	593µs	592µs	626µs	glsrgb	readpix_um_bgra_null
  32/32  MB	15	334µs	338µs	344µs	388µs	gl	readpix_um_rgba_srgb
  31/32  MB	9	546µs	574µs	571µs	595µs	glsrgb	readpix_um_rgba_srgb
  32/32  MB	10	332µs	340µs	340µs	351µs	gl	readpix_um_rgba_null
  31/32  MB	8	553µs	587µs	589µs	629µs	glsrgb	readpix_um_rgba_null

  54/54  MB	14	364µs	369µs	370µs	383µs	gl	writepix_um_bgra_srgb
  24/54  MB	19	278µs	290µs	288µs	294µs	glsrgb	writepix_um_bgra_srgb
  58/58  MB	14	365µs	376µs	375µs	381µs	gl	writepix_um_bgra_null
  27/58  MB	19	280µs	291µs	291µs	314µs	glsrgb	writepix_um_bgra_null
  59/59  MB	14	368µs	374µs	375µs	382µs	gl	writepix_um_rgba_srgb
  27/59  MB	19	280µs	298µs	295µs	324µs	glsrgb	writepix_um_rgba_srgb
  62/62  MB	14	367µs	378µs	376µs	384µs	gl	writepix_um_rgba_null
  30/62  MB	16	289µs	293µs	296µs	310µs	glsrgb	writepix_um_rgba_null

Bug: skia:
Change-Id: I36e4f68e60a39087c07cf5ff63045a29b56da8f7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/202703
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2019-03-22 12:16:40 +00:00

69 lines
2.4 KiB
C++

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Benchmark.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkString.h"
// Time variants of write-pixels
// [ colortype ][ alphatype ][ colorspace ]
// Different combinations can trigger fast or slow paths in the impls
//
class WritePixelsBench : public Benchmark {
public:
WritePixelsBench(SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs)
: fColorType(ct)
, fAlphaType(at)
, fCS(cs)
{
fName.printf("writepix_%s_%s_%s",
at == kPremul_SkAlphaType ? "pm" : "um",
ct == kRGBA_8888_SkColorType ? "rgba" : "bgra",
cs ? "srgb" : "null");
}
protected:
const char* onGetName() override {
return fName.c_str();
}
void onDraw(int loops, SkCanvas* canvas) override {
SkISize size = canvas->getBaseLayerSize();
SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), fColorType, fAlphaType,
fCS);
SkBitmap bmp;
bmp.allocPixels(info);
bmp.eraseColor(SK_ColorBLACK);
for (int loop = 0; loop < loops; ++loop) {
canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0);
}
}
private:
SkColorType fColorType;
SkAlphaType fAlphaType;
sk_sp<SkColorSpace> fCS;
SkString fName;
typedef Benchmark INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);)
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr);)
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());)
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());)
DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, nullptr);)
DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr);)
DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());)
DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());)