Bench baseline for mostly 0 image.

Add a baseline for decoding a mostly 0 image. This is in advance of
https://codereview.chromium.org/24269006/ which provides an option to
skip writing those 0s (as part of BUG=skia:1661). On my Nexus 4, the
benchmark does not slow down after that change.

As suggested in https://codereview.chromium.org/24269006/ add a
resourcePath flag to bench. Will require a change in buildbot in order
to actually use the flag.

Add an image used by the test.

Until https://codereview.chromium.org/24448002 is submitted,
the test will not actually be run by the bots (since it
won't know where to find the file).

BUG=skia:1661
R=djsollen@google.com, mtklein@google.com

Review URL: https://codereview.chromium.org/24440002

git-svn-id: http://skia.googlecode.com/svn/trunk@11461 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
scroggo@google.com 2013-09-25 21:42:12 +00:00
parent b5571b3324
commit 111fd11e11
6 changed files with 130 additions and 1 deletions

View File

@ -1,4 +1,3 @@
/*
* Copyright 2011 Google Inc.
*
@ -15,6 +14,8 @@ SK_DEFINE_INST_COUNT(SkBenchmark)
template BenchRegistry* BenchRegistry::gHead;
SkString SkBenchmark::gResourcePath;
SkBenchmark::SkBenchmark() {
fForceAlpha = 0xFF;
fForceAA = true;

View File

@ -10,6 +10,7 @@
#include "SkRefCnt.h"
#include "SkPoint.h"
#include "SkString.h"
#include "SkTRegistry.h"
#define DEF_BENCH(code) \
@ -106,6 +107,10 @@ public:
// for (int i = 0; i < this->getLoops(); i++) { <work here> }
int getLoops() const { return fLoops; }
static void SetResourcePath(const char* resPath) { gResourcePath.set(resPath); }
static SkString& GetResourcePath() { return gResourcePath; }
protected:
virtual void setupPaint(SkPaint* paint);
@ -125,6 +130,7 @@ private:
SkTriState::State fDither;
uint32_t fOrMask, fClearMask;
int fLoops;
static SkString gResourcePath;
typedef SkRefCnt INHERITED;
};

115
bench/SkipZeroesBench.cpp Normal file
View File

@ -0,0 +1,115 @@
/*
* 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 "SkBenchmark.h"
#include "SkBitmap.h"
#include "SkData.h"
#include "SkForceLinking.h"
#include "SkImageDecoder.h"
#include "SkOSFile.h"
#include "SkStream.h"
#include "SkString.h"
__SK_FORCE_IMAGE_DECODER_LINKING;
class SkCanvas;
class SkipZeroesBench : public SkBenchmark {
public:
SkipZeroesBench(const char* filename, bool skipZeroes)
: fName("SkipZeroes_")
, fDecoder(NULL)
, fFilename(filename)
, fStream()
, fSkipZeroes(skipZeroes)
, fValid(false) {
fName.append(filename);
if (skipZeroes) {
fName.append("_skip_zeroes");
} else {
fName.append("_write_zeroes");
}
fIsRendering = false;
}
protected:
virtual const char* onGetName() SK_OVERRIDE {
return fName.c_str();
}
virtual void onPreDraw() SK_OVERRIDE {
const char* resPath = GetResourcePath().c_str();
if (NULL == resPath) {
fValid = false;
return;
}
SkString fullPath = SkOSPath::SkPathJoin(resPath, fFilename.c_str());
SkFILEStream fileStream(fullPath.c_str());
fValid = fileStream.isValid() && fileStream.getLength() > 0;
if (fValid) {
const size_t size = fileStream.getLength();
void* data = sk_malloc_throw(size);
if (fileStream.read(data, size) < size) {
fValid = false;
} else {
SkAutoTUnref<SkData> skdata(SkData::NewFromMalloc(data, size));
fStream.setData(skdata.get());
fDecoder.reset(SkImageDecoder::Factory(&fStream));
if (fDecoder.get()) {
// Disabling until the feature is checked in.
// See https://codereview.chromium.org/24269006/
//fDecoder->setSkipWritingZeroes(fSkipZeroes);
} else {
fValid = false;
}
}
}
}
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
if (!fValid) {
#ifdef SK_DEBUG
SkDebugf("stream was invalid: %s\n", fFilename.c_str());
#endif
return;
}
// Decode a bunch of times
SkBitmap bm;
for (int i = 0; i < this->getLoops(); ++i) {
SkDEBUGCODE(bool success =) fDecoder->decode(&fStream, &bm,
SkImageDecoder::kDecodePixels_Mode);
#ifdef SK_DEBUG
if (!success) {
SkDebugf("failed to decode %s\n", fFilename.c_str());
return;
}
#endif
SkDEBUGCODE(success =) fStream.rewind();
#ifdef SK_DEBUG
if (!success) {
SkDebugf("failed to rewind %s\n", fFilename.c_str());
return;
}
#endif
}
}
private:
SkString fName;
SkAutoTDelete<SkImageDecoder> fDecoder;
const SkString fFilename;
SkMemoryStream fStream;
bool fSkipZeroes;
bool fValid;
typedef SkBenchmark INHERITED;
};
// Enable the true version once the feature is checked in.
//DEF_BENCH( return SkNEW_ARGS(SkipZeroesBench, ("arrow.png", true)));
DEF_BENCH( return SkNEW_ARGS(SkipZeroesBench, ("arrow.png", false)));

View File

@ -284,6 +284,7 @@ DEFINE_double(error, 0.01,
"Ratio of subsequent bench measurements must drop within 1±error to converge.");
DEFINE_string(timeFormat, "%9.2f", "Format to print results, in milliseconds per 1000 loops.");
DEFINE_bool2(verbose, v, false, "Print more.");
DEFINE_string2(resourcePath, i, NULL, "directory for test resources.");
// Has this bench converged? First arguments are milliseconds / loop iteration,
// last is overall runtime in milliseconds.
@ -357,6 +358,11 @@ int tool_main(int argc, char** argv) {
}
}
}
// Set the resource path.
if (!FLAGS_resourcePath.isEmpty()) {
SkBenchmark::SetResourcePath(FLAGS_resourcePath[0]);
}
#if SK_SUPPORT_GPU
for (int i = 0; i < configs.count(); ++i) {
const Config& config = gConfigs[configs[i]];

View File

@ -62,6 +62,7 @@
'../bench/RTreeBench.cpp',
'../bench/ScalarBench.cpp',
'../bench/ShaderMaskBench.cpp',
'../bench/SkipZeroesBench.cpp',
'../bench/SortBench.cpp',
'../bench/StrokeBench.cpp',
'../bench/TableBench.cpp',

BIN
resources/arrow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB