- Use FLAGS_.
   - Remove outer repeat loop.
   - Tune inner loop automatically.

BUG=skia:1590
R=epoger@google.com, scroggo@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@11187 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
mtklein@google.com 2013-09-10 19:23:38 +00:00
Родитель 55ebe8eca0
Коммит c289743864
71 изменённых файлов: 647 добавлений и 1186 удалений

Просмотреть файл

@ -23,10 +23,6 @@ class AAClipBench : public SkBenchmark {
bool fDoPath;
bool fDoAA;
enum {
N = SkBENCHLOOP(200),
};
public:
AAClipBench(void* param, bool doPath, bool doAA)
: INHERITED(param)
@ -53,7 +49,7 @@ protected:
SkPaint paint;
this->setupPaint(&paint);
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
// jostle the clip regions each time to prevent caching
fClipRect.offset((i % 2) == 0 ? SkIntToScalar(10) : SkIntToScalar(-10), 0);
fClipPath.reset();
@ -96,7 +92,6 @@ class NestedAAClipBench : public SkBenchmark {
SkRect fDrawRect;
SkRandom fRandom;
static const int kNumDraws = SkBENCHLOOP(2);
static const int kNestingDepth = 3;
static const int kImageSize = 400;
@ -169,7 +164,7 @@ protected:
virtual void onDraw(SkCanvas* canvas) {
for (int i = 0; i < kNumDraws; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkPoint offset = SkPoint::Make(0, 0);
this->recurse(canvas, 0, offset);
}
@ -188,10 +183,6 @@ class AAClipBuilderBench : public SkBenchmark {
bool fDoPath;
bool fDoAA;
enum {
N = SkBENCHLOOP(200),
};
public:
AAClipBuilderBench(void* param, bool doPath, bool doAA) : INHERITED(param) {
fDoPath = doPath;
@ -212,7 +203,7 @@ protected:
SkPaint paint;
this->setupPaint(&paint);
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkAAClip clip;
if (fDoPath) {
clip.setPath(fPath, &fRegion, fDoAA);
@ -244,16 +235,13 @@ public:
protected:
virtual const char* onGetName() { return "aaclip_setregion"; }
virtual void onDraw(SkCanvas*) {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkAAClip clip;
clip.setRegion(fRegion);
}
}
private:
enum {
N = SkBENCHLOOP(400),
};
SkRegion fRegion;
typedef SkBenchmark INHERITED;
};

Просмотреть файл

@ -7,7 +7,6 @@
#include "SkBenchmark.h"
#include "SkCanvas.h"
#include "SkRandom.h"
#include "SkShader.h"
#include "SkString.h"
#include "SkBicubicImageFilter.h"
@ -37,14 +36,16 @@ protected:
paint.setAntiAlias(true);
SkRandom rand;
SkRect r = SkRect::MakeWH(40, 40);
SkAutoTUnref<SkImageFilter> bicubic(SkBicubicImageFilter::CreateMitchell(fScale));
paint.setImageFilter(bicubic);
canvas->save();
canvas->clipRect(r);
canvas->drawOval(r, paint);
canvas->restore();
for (int i = 0; i < this->getLoops(); i++) {
canvas->save();
canvas->clipRect(r);
canvas->drawOval(r, paint);
canvas->restore();
}
}
private:

Просмотреть файл

@ -81,8 +81,6 @@ class BitmapBench : public SkBenchmark {
bool fIsVolatile;
SkBitmap::Config fConfig;
SkString fName;
enum { BICUBIC_DUR_SCALE = 20 };
enum { N = SkBENCHLOOP(15 * BICUBIC_DUR_SCALE) };
enum { W = 128 };
enum { H = 128 };
public:
@ -146,14 +144,7 @@ protected:
const SkScalar x0 = SkIntToScalar(-bitmap.width() / 2);
const SkScalar y0 = SkIntToScalar(-bitmap.height() / 2);
int count = N;
#ifdef SK_RELEASE
// in DEBUG, N is always 1
if (SkPaint::kHigh_FilterLevel == paint.getFilterLevel()) {
count /= BICUBIC_DUR_SCALE;
}
#endif
for (int i = 0; i < count; i++) {
for (int i = 0; i < this->getLoops(); i++) {
SkScalar x = x0 + rand.nextUScalar1() * dim.fX;
SkScalar y = y0 + rand.nextUScalar1() * dim.fY;
@ -164,17 +155,6 @@ protected:
}
}
virtual float onGetDurationScale() SK_OVERRIDE {
SkPaint paint;
this->setupPaint(&paint);
#ifdef SK_DEBUG
return 1;
#else
return SkPaint::kHigh_FilterLevel == paint.getFilterLevel() ?
(float)BICUBIC_DUR_SCALE : 1;
#endif
}
virtual void onDrawIntoBitmap(const SkBitmap& bm) {
const int w = bm.width();
const int h = bm.height();
@ -219,7 +199,6 @@ static bool isBicubic(uint32_t flags) {
class FilterBitmapBench : public BitmapBench {
uint32_t fFlags;
SkString fFullName;
enum { N = SkBENCHLOOP(300) };
public:
FilterBitmapBench(void* param, bool isOpaque, SkBitmap::Config c,
bool forceUpdate, bool isVolitile, uint32_t flags)

Просмотреть файл

@ -47,7 +47,6 @@ class BitmapRectBench : public SkBenchmark {
SkRect fSrcR, fDstR;
static const int kWidth = 128;
static const int kHeight = 128;
enum { N = SkBENCHLOOP(300) };
public:
BitmapRectBench(void* param, U8CPU alpha, bool doFilter, bool slightMatrix) : INHERITED(param) {
fAlpha = SkToU8(alpha);
@ -93,7 +92,7 @@ protected:
paint.setFilterBitmap(fDoFilter);
paint.setAlpha(fAlpha);
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
canvas->drawBitmapRectToRect(fBitmap, &fSrcR, fDstR, &paint);
}
}

Просмотреть файл

@ -75,7 +75,7 @@ protected:
preBenchSetup();
for (int i = 0; i < SkBENCHLOOP(fLoopCount); i++) {
for (int i = 0; i < this->getLoops(); i++) {
doScaleImage();
}
}

Просмотреть файл

@ -60,7 +60,7 @@ protected:
paint.setAntiAlias(true);
SkRandom rand;
for (int i = 0; i < SkBENCHLOOP(10); i++) {
for (int i = 0; i < this->getLoops(); i++) {
SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
rand.nextUScalar1() * 400);
r.offset(fRadius, fRadius);

Просмотреть файл

@ -44,7 +44,10 @@ protected:
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkPaint paint;
paint.setImageFilter(new SkBlurImageFilter(fSigmaX, fSigmaY))->unref();
canvas->drawBitmap(fCheckerboard, 0, 0, &paint);
for (int i = 0; i < this->getLoops(); i++) {
canvas->drawBitmap(fCheckerboard, 0, 0, &paint);
}
}
private:

Просмотреть файл

@ -62,7 +62,7 @@ protected:
preBenchSetup(r);
for (int i = 0; i < SkBENCHLOOP(fLoopCount); i++) {
for (int i = 0; i < this->getLoops(); i++) {
makeBlurryRect(r);
}
}

Просмотреть файл

@ -127,7 +127,7 @@ protected:
}
}
for (int frame = 0; frame < kFramesPerRun; ++frame) {
for (int frame = 0; frame < this->getLoops(); ++frame) {
canvas->clear(0xFFE0F0E0);
@ -183,8 +183,6 @@ private:
kNumGraphs = 5,
kPixelsPerTick = 3,
kShiftPerFrame = 1,
kFramesPerRun = SkBENCHLOOP(5),
};
int fShift;
SkISize fSize;

Просмотреть файл

@ -23,7 +23,6 @@ class ComputeChecksumBench : public SkBenchmark {
enum {
U32COUNT = 256,
SIZE = U32COUNT * 4,
N = SkBENCHLOOP(100000),
};
uint32_t fData[U32COUNT];
ChecksumType fType;
@ -52,13 +51,13 @@ protected:
virtual void onDraw(SkCanvas*) {
switch (fType) {
case kChecksum_ChecksumType: {
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
volatile uint32_t result = SkChecksum::Compute(fData, sizeof(fData));
sk_ignore_unused_variable(result);
}
} break;
case kMD5_ChecksumType: {
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
SkMD5 md5;
md5.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData));
SkMD5::Digest digest;
@ -66,7 +65,7 @@ protected:
}
} break;
case kSHA1_ChecksumType: {
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
SkSHA1 sha1;
sha1.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData));
SkSHA1::Digest digest;
@ -74,7 +73,7 @@ protected:
}
} break;
case kMurmur3_ChecksumType: {
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
volatile uint32_t result = SkChecksum::Murmur3(fData, sizeof(fData));
sk_ignore_unused_variable(result);
}

Просмотреть файл

@ -468,7 +468,7 @@ protected:
for (int i = 0; i < N; i++) {
SkRect current;
setRectangle(current, i);
for (int j = 0; j < SkBENCHLOOP(gmailScrollingRectSpec[i*3]); j++) {
for (int j = 0; j < this->getLoops() * gmailScrollingRectSpec[i*3]; j++) {
canvas->drawRect(current, paint);
}
}

Просмотреть файл

@ -11,7 +11,6 @@
#include "SkTypeface.h"
enum {
LOOP = SkBENCHLOOP(1000),
NGLYPHS = 100
};
@ -21,44 +20,44 @@ static SkTypeface::Encoding paint2Encoding(const SkPaint& paint) {
return (SkTypeface::Encoding)enc;
}
typedef void (*TypefaceProc)(const SkPaint&, const void* text, size_t len,
typedef void (*TypefaceProc)(int loops, const SkPaint&, const void* text, size_t len,
int glyphCount);
static void containsText_proc(const SkPaint& paint, const void* text, size_t len,
static void containsText_proc(int loops, const SkPaint& paint, const void* text, size_t len,
int glyphCount) {
for (int i = 0; i < LOOP; ++i) {
for (int i = 0; i < loops; ++i) {
paint.containsText(text, len);
}
}
static void textToGlyphs_proc(const SkPaint& paint, const void* text, size_t len,
static void textToGlyphs_proc(int loops, const SkPaint& paint, const void* text, size_t len,
int glyphCount) {
uint16_t glyphs[NGLYPHS];
SkASSERT(glyphCount <= NGLYPHS);
for (int i = 0; i < LOOP; ++i) {
for (int i = 0; i < loops; ++i) {
paint.textToGlyphs(text, len, glyphs);
}
}
static void charsToGlyphs_proc(const SkPaint& paint, const void* text,
static void charsToGlyphs_proc(int loops, const SkPaint& paint, const void* text,
size_t len, int glyphCount) {
SkTypeface::Encoding encoding = paint2Encoding(paint);
uint16_t glyphs[NGLYPHS];
SkASSERT(glyphCount <= NGLYPHS);
SkTypeface* face = paint.getTypeface();
for (int i = 0; i < LOOP; ++i) {
for (int i = 0; i < loops; ++i) {
face->charsToGlyphs(text, encoding, glyphs, glyphCount);
}
}
static void charsToGlyphsNull_proc(const SkPaint& paint, const void* text,
static void charsToGlyphsNull_proc(int loops, const SkPaint& paint, const void* text,
size_t len, int glyphCount) {
SkTypeface::Encoding encoding = paint2Encoding(paint);
SkTypeface* face = paint.getTypeface();
for (int i = 0; i < LOOP; ++i) {
for (int i = 0; i < loops; ++i) {
face->charsToGlyphs(text, encoding, NULL, glyphCount);
}
}
@ -87,7 +86,7 @@ protected:
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
fProc(fPaint, fText, sizeof(fText), NGLYPHS);
fProc(this->getLoops(), fPaint, fText, sizeof(fText), NGLYPHS);
}
private:

Просмотреть файл

@ -76,11 +76,14 @@ protected:
SkRect r = getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
for (float brightness = -1.0f; brightness <= 1.0f; brightness += 0.4f) {
SkAutoTUnref<SkImageFilter> dim(make_brightness(-brightness));
SkAutoTUnref<SkImageFilter> bright(make_brightness(brightness, dim));
paint.setImageFilter(bright);
canvas->drawRect(r, paint);
for (int i = 0; i < this->getLoops(); i++) {
for (float brightness = -1.0f; brightness <= 1.0f; brightness += 0.4f) {
SkAutoTUnref<SkImageFilter> dim(make_brightness(-brightness));
SkAutoTUnref<SkImageFilter> bright(make_brightness(brightness, dim));
paint.setImageFilter(bright);
canvas->drawRect(r, paint);
}
}
}
@ -103,7 +106,7 @@ protected:
SkRect r = getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
{
for (int i = 0; i < this->getLoops(); i++) {
SkAutoTUnref<SkImageFilter> brightness(make_brightness(0.9f));
SkAutoTUnref<SkImageFilter> grayscale(make_grayscale(brightness));
paint.setImageFilter(grayscale);
@ -130,7 +133,7 @@ protected:
SkRect r = getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
{
for (int i = 0; i < this->getLoops(); i++) {
SkAutoTUnref<SkImageFilter> grayscale(make_grayscale());
SkAutoTUnref<SkImageFilter> brightness(make_brightness(0.9f, grayscale));
paint.setImageFilter(brightness);
@ -157,7 +160,7 @@ protected:
SkRect r = getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
{
for (int i = 0; i < this->getLoops(); i++) {
SkAutoTUnref<SkImageFilter> blue(make_mode_blue());
SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f, blue));
paint.setImageFilter(brightness);
@ -184,7 +187,7 @@ protected:
SkRect r = getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
{
for (int i = 0; i < this->getLoops(); i++) {
SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f));
SkAutoTUnref<SkImageFilter> blue(make_mode_blue(brightness));
paint.setImageFilter(blue);
@ -211,7 +214,7 @@ protected:
SkRect r = getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
{
for (int i = 0; i < this->getLoops(); i++) {
SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f));
paint.setImageFilter(brightness);
canvas->drawRect(r, paint);
@ -237,7 +240,7 @@ protected:
SkRect r = getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
{
for (int i = 0; i < this->getLoops(); i++) {
SkAutoTUnref<SkImageFilter> blue(make_mode_blue());
paint.setImageFilter(blue);
canvas->drawRect(r, paint);
@ -263,7 +266,7 @@ protected:
SkRect r = getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
{
for (int i = 0; i < this->getLoops(); i++) {
SkAutoTUnref<SkImageFilter> grayscale(make_grayscale());
paint.setImageFilter(grayscale);
canvas->drawRect(r, paint);
@ -289,7 +292,7 @@ protected:
SkRect r = getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
{
for (int i = 0; i < this->getLoops(); i++) {
SkAutoTUnref<SkColorFilter> table_filter(make_table_filter());
paint.setColorFilter(table_filter);
canvas->drawRect(r, paint);

Просмотреть файл

@ -37,9 +37,6 @@ protected:
SkPoint fPts[2];
bool fDoClip;
enum {
N = SkBENCHLOOP(100)
};
public:
DashBench(void* param, const SkScalar intervals[], int count, int width,
bool doClip = false) : INHERITED(param) {
@ -85,7 +82,7 @@ protected:
canvas->clipRect(r);
}
this->handlePath(canvas, path, paint, N);
this->handlePath(canvas, path, paint, this->getLoops());
}
virtual void handlePath(SkCanvas* canvas, const SkPath& path,
@ -183,10 +180,6 @@ class MakeDashBench : public SkBenchmark {
SkPath fPath;
SkAutoTUnref<SkPathEffect> fPE;
enum {
N = SkBENCHLOOP(400)
};
public:
MakeDashBench(void* param, void (*proc)(SkPath*), const char name[]) : INHERITED(param) {
fName.printf("makedash_%s", name);
@ -203,7 +196,7 @@ protected:
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
SkPath dst;
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle);
fPE->filterPath(&dst, fPath, &rec, NULL);
@ -224,10 +217,6 @@ class DashLineBench : public SkBenchmark {
bool fIsRound;
SkAutoTUnref<SkPathEffect> fPE;
enum {
N = SkBENCHLOOP(200)
};
public:
DashLineBench(void* param, SkScalar width, bool isRound) : INHERITED(param) {
fName.printf("dashline_%g_%s", SkScalarToFloat(width), isRound ? "circle" : "square");
@ -249,7 +238,7 @@ protected:
paint.setStrokeWidth(fStrokeWidth);
paint.setStrokeCap(fIsRound ? SkPaint::kRound_Cap : SkPaint::kSquare_Cap);
paint.setPathEffect(fPE);
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
canvas->drawLine(10 * SK_Scalar1, 10 * SK_Scalar1,
640 * SK_Scalar1, 10 * SK_Scalar1, paint);
}
@ -266,10 +255,6 @@ class DrawPointsDashingBench : public SkBenchmark {
SkAutoTUnref<SkPathEffect> fPathEffect;
enum {
N = SkBENCHLOOP(480)
};
public:
DrawPointsDashingBench(void* param, int dashLength, int strokeWidth, bool doAA)
: INHERITED(param) {
@ -287,7 +272,6 @@ protected:
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkPaint p;
this->setupPaint(&p);
p.setColor(SK_ColorBLACK);
@ -301,8 +285,7 @@ protected:
{ SkIntToScalar(640), 0 }
};
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
pts[0].fY = pts[1].fY = SkIntToScalar(i % 480);
canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p);
}
@ -381,7 +364,9 @@ protected:
p.setStrokeWidth(fStrokeWidth);
p.setPathEffect(fPathEffect);
canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, p);
for (int i = 0; i < this->getLoops(); i++) {
canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, p);
}
}
private:

Просмотреть файл

@ -7,29 +7,26 @@
*/
#include "SkBenchmark.h"
#include "SkBitmap.h"
#include "SkCommandLineFlags.h"
#include "SkImageDecoder.h"
#include "SkString.h"
DEFINE_string(decodeBenchFilename, "resources/CMYK.jpeg", "Path to image for DecodeBench.");
static const char* gConfigName[] = {
"ERROR", "a1", "a8", "index8", "565", "4444", "8888"
};
class DecodeBench : public SkBenchmark {
const char* fFilename;
SkBitmap::Config fPrefConfig;
SkString fName;
enum { N = SkBENCHLOOP(10) };
public:
DecodeBench(void* param, SkBitmap::Config c) : SkBenchmark(param) {
fFilename = this->findDefine("decode-filename");
fPrefConfig = c;
const char* fname = NULL;
if (fFilename) {
fname = strrchr(fFilename, '/');
if (fname) {
fname += 1; // skip the slash
}
const char* fname = strrchr(FLAGS_decodeBenchFilename[0], '/');
if (fname) {
fname++; // skip the slash
}
fName.printf("decode_%s_%s", gConfigName[c], fname);
fIsRendering = false;
@ -41,12 +38,12 @@ protected:
}
virtual void onDraw(SkCanvas*) {
if (fFilename) {
for (int i = 0; i < N; i++) {
SkBitmap bm;
SkImageDecoder::DecodeFile(fFilename, &bm, fPrefConfig,
SkImageDecoder::kDecodePixels_Mode);
}
for (int i = 0; i < this->getLoops(); i++) {
SkBitmap bm;
SkImageDecoder::DecodeFile(FLAGS_decodeBenchFilename[0],
&bm,
fPrefConfig,
SkImageDecoder::kDecodePixels_Mode);
}
}

Просмотреть файл

@ -16,7 +16,6 @@ public:
}
enum {
N = SkBENCHLOOP(25), // number of times to create the picture
CANVAS_WIDTH = 200,
CANVAS_HEIGHT = 200,
};
@ -34,7 +33,7 @@ protected:
initDeferredCanvas(deferredCanvas);
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
drawInDeferredCanvas(deferredCanvas);
}
@ -75,9 +74,6 @@ public:
: INHERITED(param, "record") {
}
enum {
M = SkBENCHLOOP(700), // number of individual draws in each loop
};
protected:
virtual void initDeferredCanvas(SkDeferredCanvas* canvas) SK_OVERRIDE {
@ -88,7 +84,7 @@ protected:
SkRect rect;
rect.setXYWH(0, 0, 10, 10);
SkPaint paint;
for (int i = 0; i < M; i++) {
for (int i = 0; i < this->getLoops(); i++) {
canvas->save(SkCanvas::kMatrixClip_SaveFlag);
canvas->translate(SkIntToScalar(i * 27 % CANVAS_WIDTH), SkIntToScalar(i * 13 % CANVAS_HEIGHT));
canvas->drawRect(rect, paint);

Просмотреть файл

@ -17,7 +17,6 @@
class DeferredSurfaceCopyBench : public SkBenchmark {
enum {
N = SkBENCHLOOP(5),
kSurfaceWidth = 1000,
kSurfaceHeight = 1000,
};
@ -56,7 +55,7 @@ protected:
SkAutoTUnref<SkDeferredCanvas> drawingCanvas(SkDeferredCanvas::Create(surface));
surface->unref();
for (int iteration = 0; iteration < N; iteration++) {
for (int iteration = 0; iteration < this->getLoops(); iteration++) {
drawingCanvas->clear(0);
SkAutoTUnref<SkImage> image(drawingCanvas->newImageSnapshot());
SkPaint paint;

Просмотреть файл

@ -105,7 +105,10 @@ protected:
paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
(SkDisplacementMapEffect::kR_ChannelSelectorType,
SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ)))->unref();
drawClippedBitmap(canvas, 0, 0, paint);
for (int i = 0; i < this->getLoops(); i++) {
drawClippedBitmap(canvas, 0, 0, paint);
}
}
private:
@ -129,7 +132,9 @@ protected:
paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
(SkDisplacementMapEffect::kB_ChannelSelectorType,
SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ)))->unref();
drawClippedBitmap(canvas, 100, 0, paint);
for (int i = 0; i < this->getLoops(); i++) {
drawClippedBitmap(canvas, 100, 0, paint);
}
}
private:
@ -153,7 +158,9 @@ protected:
paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
(SkDisplacementMapEffect::kR_ChannelSelectorType,
SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ)))->unref();
drawClippedBitmap(canvas, 200, 0, paint);
for (int i = 0; i < this->getLoops(); i++) {
drawClippedBitmap(canvas, 200, 0, paint);
}
}
private:

Просмотреть файл

@ -44,9 +44,9 @@ protected:
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkPaint paint;
for (int i = 0; i < N; ++i) {
paint.setColor(fColors[i]);
canvas->drawRect(fRects[i], paint);
for (int i = 0; i < this->getLoops(); ++i) {
paint.setColor(fColors[i % N]);
canvas->drawRect(fRects[i % N], paint);
}
}
@ -54,7 +54,7 @@ private:
enum {
W = 640,
H = 480,
N = SkBENCHLOOP(300)
N = 300,
};
SkRect fRects[N];
SkColor fColors[N];

Просмотреть файл

@ -24,10 +24,6 @@ static int count_glyphs(const uint16_t start[]) {
}
class FontCacheBench : public SkBenchmark {
enum {
N = SkBENCHLOOP(50)
};
public:
FontCacheBench(void* param) : INHERITED(param) {}
@ -44,7 +40,7 @@ protected:
const uint16_t* array = gUniqueGlyphIDs;
while (*array != gUniqueGlyphIDs_Sentinel) {
size_t count = count_glyphs(array);
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
paint.measureText(array, count * sizeof(uint16_t));
}
array += count + 1; // skip the sentinel

Просмотреть файл

@ -35,14 +35,16 @@ protected:
bool prev = gSkSuppressFontCachePurgeSpew;
gSkSuppressFontCachePurgeSpew = true;
// this is critical - we want to time the creation process, so we
// explicitly flush our cache before each run
SkGraphics::PurgeFontCache();
for (int i = 0; i < this->getLoops(); i++) {
// this is critical - we want to time the creation process, so we
// explicitly flush our cache before each run
SkGraphics::PurgeFontCache();
for (int ps = 9; ps <= 24; ps += 2) {
paint.setTextSize(SkIntToScalar(ps));
canvas->drawText(fText.c_str(), fText.size(),
0, SkIntToScalar(20), paint);
for (int ps = 9; ps <= 24; ps += 2) {
paint.setTextSize(SkIntToScalar(ps));
canvas->drawText(fText.c_str(), fText.size(),
0, SkIntToScalar(20), paint);
}
}
gSkSuppressFontCachePurgeSpew = prev;

Просмотреть файл

@ -144,8 +144,7 @@ protected:
SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode))->unref();
for (int i = 0; i < kNumRects; ++i, ++fNumSaved) {
for (int i = 0; i < this->getLoops(); ++i, ++fNumSaved) {
if (0 == i % kNumBeforeClear) {
if (kPartial_Clear == fClear) {
for (int j = 0; j < fNumSaved; ++j) {
@ -229,15 +228,7 @@ private:
(kNumAtlasedX+1) * kAtlasSpacer;
static const int kTotAtlasHeight = kNumAtlasedY * kAtlasCellHeight +
(kNumAtlasedY+1) * kAtlasSpacer;
#ifdef SK_DEBUG
static const int kNumRects = 100;
static const int kNumBeforeClear = 10;
#else
static const int kNumRects = 5000;
static const int kNumBeforeClear = 300;
#endif
static const int kNumBeforeClear = 100;
Type fType;
Clear fClear;

Просмотреть файл

@ -34,9 +34,6 @@ GrMemoryPool A::gPool(10 * (1 << 10), 10 * (1 << 10));
* This benchmark creates and deletes objects in stack order
*/
class GrMemoryPoolBenchStack : public SkBenchmark {
enum {
N = SkBENCHLOOP(1 * (1 << 20)),
};
public:
GrMemoryPoolBenchStack(void* param) : INHERITED(param) {
fIsRendering = false;
@ -56,13 +53,11 @@ protected:
// We delete if a random [-1, 1] fixed pt is < the thresh. Otherwise,
// we allocate. We start allocate-biased and ping-pong to delete-biased
SkFixed delThresh = -SK_FixedHalf;
enum {
kSwitchThreshPeriod = N / (2 * kMaxObjects),
};
const int kSwitchThreshPeriod = this->getLoops() / (2 * kMaxObjects);
int s = 0;
int count = 0;
for (int i = 0; i < N; i++, ++s) {
for (int i = 0; i < this->getLoops(); i++, ++s) {
if (kSwitchThreshPeriod == s) {
delThresh = -delThresh;
s = 0;
@ -90,9 +85,6 @@ private:
* This benchmark creates objects and deletes them in random order
*/
class GrMemoryPoolBenchRandom : public SkBenchmark {
enum {
N = SkBENCHLOOP(1 * (1 << 20)),
};
public:
GrMemoryPoolBenchRandom(void* param) : INHERITED(param) {
fIsRendering = false;
@ -109,7 +101,7 @@ protected:
};
SkAutoTDelete<A> objects[kMaxObjects];
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
uint32_t idx = r.nextRangeU(0, kMaxObjects-1);
if (NULL == objects[idx].get()) {
objects[idx].reset(new A);
@ -128,8 +120,7 @@ private:
*/
class GrMemoryPoolBenchQueue : public SkBenchmark {
enum {
N = SkBENCHLOOP((1 << 8)),
M = SkBENCHLOOP(4 * (1 << 10)),
M = 4 * (1 << 10),
};
public:
GrMemoryPoolBenchQueue(void* param) : INHERITED(param) {
@ -143,7 +134,7 @@ protected:
virtual void onDraw(SkCanvas*) {
SkRandom r;
A* objects[M];
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
uint32_t count = r.nextRangeU(0, M-1);
for (uint32_t i = 0; i < count; i++) {
objects[i] = new A;

Просмотреть файл

@ -159,11 +159,10 @@ static const char* geomtypename(GeomType gt) {
class GradientBench : public SkBenchmark {
SkString fName;
SkShader* fShader;
int fCount;
int fRepeat;
enum {
W = 400,
H = 400,
N = 1
};
public:
GradientBench(void* param, GradType gradType,
@ -187,7 +186,7 @@ public:
{ SkIntToScalar(W), SkIntToScalar(H) }
};
fCount = SkBENCHLOOP(N * gGrads[gradType].fRepeat);
fRepeat = gGrads[gradType].fRepeat;
fShader = gGrads[gradType].fMaker(pts, data, tm, NULL, scale);
fGeomType = geomType;
}
@ -208,7 +207,7 @@ protected:
paint.setShader(fShader);
SkRect r = { 0, 0, SkIntToScalar(W), SkIntToScalar(H) };
for (int i = 0; i < fCount; i++) {
for (int i = 0; i < this->getLoops() * fRepeat; i++) {
switch (fGeomType) {
case kRect_GeomType:
canvas->drawRect(r, paint);
@ -251,7 +250,7 @@ protected:
{ SkIntToScalar(100), SkIntToScalar(100) },
};
for (int i = 0; i < SkBENCHLOOP(1000); i++) {
for (int i = 0; i < this->getLoops(); i++) {
const int gray = i % 256;
const int alpha = fHasAlpha ? gray : 0xFF;
SkColor colors[] = {

Просмотреть файл

@ -63,8 +63,7 @@ protected:
path.transform(m);
}
int count = N;
for (int i = 0; i < count; i++) {
for (int i = 0; i < this->getLoops(); i++) {
canvas->drawPath(path, paint);
}
}
@ -73,7 +72,6 @@ private:
SkPaint fPaint;
SkString fName;
Flags fFlags;
enum { N = SkBENCHLOOP(200) };
typedef SkBenchmark INHERITED;
};

Просмотреть файл

@ -13,7 +13,6 @@ class ImageCacheBench : public SkBenchmark {
SkBitmap fBM;
enum {
N = SkBENCHLOOP(1000),
DIM = 1,
CACHE_COUNT = 500
};
@ -46,7 +45,7 @@ protected:
SkBitmap tmp;
// search for a miss (-1 scale)
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
(void)fCache.findAndLock(fBM, -1, -1, &tmp);
}
}

Просмотреть файл

@ -59,7 +59,7 @@ protected:
#endif
// Decode a bunch of times
SkBitmap bm;
for (int i = 0; i < SkBENCHLOOP(1000); ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkDEBUGCODE(bool success =) SkImageDecoder::DecodeStream(&fStream, &bm);
#ifdef SK_DEBUG
if (!success) {

Просмотреть файл

@ -33,7 +33,7 @@ protected:
}
virtual void onDraw(SkCanvas*) {
int n = SkBENCHLOOP(kLoop * this->mulLoopCount());
int n = this->getLoops() * this->mulLoopCount();
for (int i = 0; i < n; i++) {
this->performTest(fDst, fFx, fDx, kBuffer);
}

Просмотреть файл

@ -26,7 +26,9 @@ protected:
SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_LARGE);
SkPaint paint;
paint.setImageFilter(imageFilter)->unref();
canvas->drawRect(r, paint);
for (int i = 0; i < this->getLoops(); i++) {
canvas->drawRect(r, paint);
}
}
static SkPoint3 getPointLocation() {

Просмотреть файл

@ -22,7 +22,6 @@ class LineBench : public SkBenchmark {
SkString fName;
enum {
PTS = 500,
N = SkBENCHLOOP(10)
};
SkPoint fPts[PTS];
@ -51,7 +50,7 @@ protected:
paint.setAntiAlias(fDoAA);
paint.setStrokeWidth(fStrokeWidth);
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
canvas->drawPoints(SkCanvas::kLines_PointMode, PTS, fPts, paint);
}
}

Просмотреть файл

@ -43,7 +43,10 @@ protected:
SkIntToScalar(h / 4),
SkIntToScalar(w / 2),
SkIntToScalar(h / 2)), 100))->unref();
canvas->drawBitmap(fCheckerboard, 0, 0, &paint);
for (int i = 0; i < this->getLoops(); i++) {
canvas->drawBitmap(fCheckerboard, 0, 0, &paint);
}
}
private:

Просмотреть файл

@ -18,7 +18,6 @@ static float fast_floor(float x) {
class MathBench : public SkBenchmark {
enum {
kBuffer = 100,
kLoop = 10000
};
SkString fName;
float fSrc[kBuffer], fDst[kBuffer];
@ -46,7 +45,7 @@ protected:
}
virtual void onDraw(SkCanvas*) {
int n = SkBENCHLOOP(kLoop * this->mulLoopCount());
int n = this->getLoops() * this->mulLoopCount();
for (int i = 0; i < n; i++) {
this->performTest(fDst, fSrc, kBuffer);
}
@ -247,8 +246,7 @@ static bool isFinite(const SkRect& r) {
class IsFiniteBench : public SkBenchmark {
enum {
N = SkBENCHLOOP(1000),
NN = SkBENCHLOOP(1000),
N = 1000,
};
float fData[N];
public:
@ -278,13 +276,13 @@ protected:
int counter = 0;
if (proc) {
for (int j = 0; j < NN; ++j) {
for (int j = 0; j < this->getLoops(); ++j) {
for (int i = 0; i < N - 4; ++i) {
counter += proc(&data[i]);
}
}
} else {
for (int j = 0; j < NN; ++j) {
for (int j = 0; j < this->getLoops(); ++j) {
for (int i = 0; i < N - 4; ++i) {
const SkRect* r = reinterpret_cast<const SkRect*>(&data[i]);
if (false) { // avoid bit rot, suppress warning
@ -314,8 +312,7 @@ private:
class FloorBench : public SkBenchmark {
enum {
ARRAY = SkBENCHLOOP(1000),
LOOP = SkBENCHLOOP(1000),
ARRAY = 1000,
};
float fData[ARRAY];
bool fFast;
@ -345,14 +342,14 @@ protected:
const float* data = fData;
if (fFast) {
for (int j = 0; j < LOOP; ++j) {
for (int j = 0; j < this->getLoops(); ++j) {
for (int i = 0; i < ARRAY; ++i) {
accum += fast_floor(data[i]);
}
this->process(accum);
}
} else {
for (int j = 0; j < LOOP; ++j) {
for (int j = 0; j < this->getLoops(); ++j) {
for (int i = 0; i < ARRAY; ++i) {
accum += sk_float_floor(data[i]);
}
@ -373,8 +370,7 @@ private:
class CLZBench : public SkBenchmark {
enum {
ARRAY = SkBENCHLOOP(1000),
LOOP = SkBENCHLOOP(5000),
ARRAY = 1000,
};
uint32_t fData[ARRAY];
bool fUsePortable;
@ -405,14 +401,14 @@ protected:
int accum = 0;
if (fUsePortable) {
for (int j = 0; j < LOOP; ++j) {
for (int j = 0; j < this->getLoops(); ++j) {
for (int i = 0; i < ARRAY; ++i) {
accum += SkCLZ_portable(fData[i]);
}
this->process(accum);
}
} else {
for (int j = 0; j < LOOP; ++j) {
for (int j = 0; j < this->getLoops(); ++j) {
for (int i = 0; i < ARRAY; ++i) {
accum += SkCLZ(fData[i]);
}
@ -435,8 +431,7 @@ private:
class NormalizeBench : public SkBenchmark {
enum {
ARRAY = SkBENCHLOOP(1000),
LOOP = SkBENCHLOOP(1000),
ARRAY =1000,
};
SkVector fVec[ARRAY];
@ -460,7 +455,7 @@ protected:
virtual void onDraw(SkCanvas*) {
int accum = 0;
for (int j = 0; j < LOOP; ++j) {
for (int j = 0; j < this->getLoops(); ++j) {
for (int i = 0; i < ARRAY; ++i) {
accum += fVec[i].normalize();
}
@ -482,8 +477,7 @@ private:
class FixedMathBench : public SkBenchmark {
enum {
N = SkBENCHLOOP(1000),
NN = SkBENCHLOOP(1000),
N = 1000,
};
float fData[N];
SkFixed fResult[N];
@ -491,8 +485,8 @@ public:
FixedMathBench(void* param) : INHERITED(param) {
SkRandom rand;
for (int i = 0; i < N; ++i) {
fData[i] = rand.nextSScalar1();
for (int i = 0; i < this->getLoops(); ++i) {
fData[i%N] = rand.nextSScalar1();
}
fIsRendering = false;
@ -500,7 +494,7 @@ public:
protected:
virtual void onDraw(SkCanvas*) {
for (int j = 0; j < NN; ++j) {
for (int j = 0; j < this->getLoops(); ++j) {
for (int i = 0; i < N - 4; ++i) {
fResult[i] = SkFloatToFixed(fData[i]);
}

Просмотреть файл

@ -12,7 +12,6 @@
class Matrix44Bench : public SkBenchmark {
SkString fName;
enum { N = 10000 };
public:
Matrix44Bench(void* param, const char name[]) : INHERITED(param) {
fName.printf("matrix44_%s", name);
@ -29,8 +28,7 @@ protected:
}
virtual void onDraw(SkCanvas*) {
int n = SkBENCHLOOP(N * this->mulLoopCount());
for (int i = 0; i < n; i++) {
for (int i = 0; i < this->getLoops(); i++) {
this->performTest();
}
}

Просмотреть файл

@ -13,7 +13,6 @@
class MatrixBench : public SkBenchmark {
SkString fName;
enum { N = 100000 };
public:
MatrixBench(void* param, const char name[]) : INHERITED(param) {
fName.printf("matrix_%s", name);
@ -30,8 +29,7 @@ protected:
}
virtual void onDraw(SkCanvas*) {
int n = SkBENCHLOOP(N * this->mulLoopCount());
for (int i = 0; i < n; i++) {
for (int i = 0; i < this->getLoops(); i++) {
this->performTest();
}
}
@ -297,11 +295,11 @@ class ScaleTransMixedMatrixBench : public MatrixBench {
}
private:
enum {
kCount = SkBENCHLOOP(16)
kCount = 16
};
SkMatrix fMatrix;
SkPoint fSrc [16];
SkPoint fDst [16];
SkPoint fSrc [kCount];
SkPoint fDst [kCount];
SkRandom fRandom;
typedef MatrixBench INHERITED;
};
@ -337,11 +335,11 @@ class ScaleTransDoubleMatrixBench : public MatrixBench {
}
private:
enum {
kCount = SkBENCHLOOP(16)
kCount = 16
};
double fMatrix [9];
SkPoint fSrc [16];
SkPoint fDst [16];
SkPoint fSrc [kCount];
SkPoint fDst [kCount];
SkRandom fRandom;
typedef MatrixBench INHERITED;
};

Просмотреть файл

@ -40,7 +40,7 @@ protected:
this->setupPaint(&paint);
paint.setAntiAlias(true);
SkRandom rand;
for (int i = 0; i < SkBENCHLOOP(3); i++) {
for (int i = 0; i < this->getLoops(); i++) {
SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
rand.nextUScalar1() * 400);
paint.setImageFilter(fFilter);

Просмотреть файл

@ -15,10 +15,6 @@
class ChunkAllocBench : public SkBenchmark {
SkString fName;
size_t fMinSize;
enum {
N = SkBENCHLOOP(1000)
};
public:
ChunkAllocBench(void* param, size_t minSize) : INHERITED(param) {
fMinSize = minSize;
@ -38,7 +34,7 @@ protected:
SkChunkAlloc alloc(fMinSize);
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
size_t size = 0;
int calls = 0;
while (size < total) {

Просмотреть файл

@ -17,7 +17,6 @@ protected:
size_t fMinSize;
size_t fMaxSize;
enum {
kLoop = 100,
kBufferSize = 10000,
VALUE32 = 0x12345678,
VALUE16 = 0x1234
@ -46,7 +45,7 @@ protected:
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
for (int i = 0; i < kLoop; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
this->performTest();
}
}

Просмотреть файл

@ -38,7 +38,9 @@ protected:
SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_LARGE);
SkPaint paint;
paint.setImageFilter(mergeBitmaps())->unref();
canvas->drawRect(r, paint);
for (int i = 0; i < this->getLoops(); i++) {
canvas->drawRect(r, paint);
}
}
private:

Просмотреть файл

@ -60,7 +60,7 @@ protected:
paint.setAntiAlias(true);
SkRandom rand;
for (int i = 0; i < SkBENCHLOOP(3); i++) {
for (int i = 0; i < this->getLoops(); i++) {
SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
rand.nextUScalar1() * 400);
r.offset(fRadius, fRadius);

Просмотреть файл

@ -8,10 +8,6 @@
#include "SkThread.h"
class MutexBench : public SkBenchmark {
enum {
N = SkBENCHLOOP(80),
M = SkBENCHLOOP(200)
};
public:
MutexBench(void* param) : INHERITED(param) {
fIsRendering = false;
@ -22,12 +18,10 @@ protected:
}
virtual void onDraw(SkCanvas*) {
for (int i = 0; i < N; i++) {
SK_DECLARE_STATIC_MUTEX(mu);
for (int j = 0; j < M; j++) {
mu.acquire();
mu.release();
}
SK_DECLARE_STATIC_MUTEX(mu);
for (int i = 0; i < this->getLoops(); i++) {
mu.acquire();
mu.release();
}
}

Просмотреть файл

@ -29,7 +29,6 @@ class PathBench : public SkBenchmark {
SkPaint fPaint;
SkString fName;
Flags fFlags;
enum { N = SkBENCHLOOP(1000) };
public:
PathBench(void* param, Flags flags) : INHERITED(param), fFlags(flags) {
fPaint.setStyle(flags & kStroke_Flag ? SkPaint::kStroke_Style :
@ -63,7 +62,7 @@ protected:
path.transform(m);
}
int count = N;
int count = this->getLoops();
if (fFlags & kBig_Flag) {
count >>= 2;
}
@ -326,8 +325,6 @@ public:
}
protected:
enum { N = SkBENCHLOOP(5000) };
virtual const char* onGetName() SK_OVERRIDE {
return "path_create";
}
@ -338,7 +335,7 @@ protected:
}
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
this->makePath(&fPaths[i & (kPathCnt - 1)]);
}
this->restartMakingPaths();
@ -365,8 +362,6 @@ public:
}
protected:
enum { N = SkBENCHLOOP(30000) };
virtual const char* onGetName() SK_OVERRIDE {
return "path_copy";
}
@ -380,7 +375,7 @@ protected:
this->finishedMakingPaths();
}
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
int idx = i & (kPathCnt - 1);
fCopies[idx] = fPaths[idx];
}
@ -409,8 +404,6 @@ public:
}
protected:
enum { N = SkBENCHLOOP(30000) };
virtual const char* onGetName() SK_OVERRIDE {
return fInPlace ? "path_transform_in_place" : "path_transform_copy";
}
@ -430,11 +423,11 @@ protected:
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
if (fInPlace) {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
fPaths[i & (kPathCnt - 1)].transform(fMatrix);
}
} else {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
int idx = i & (kPathCnt - 1);
fPaths[idx].transform(fMatrix, &fTransformed[idx]);
}
@ -466,8 +459,6 @@ public:
}
protected:
enum { N = SkBENCHLOOP(40000) };
virtual const char* onGetName() SK_OVERRIDE {
return "path_equality_50%";
}
@ -485,7 +476,7 @@ protected:
}
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
int idx = i & (kPathCnt - 1);
fParity ^= (fPaths[idx] == fCopies[idx & ~0x1]);
}
@ -525,8 +516,6 @@ public:
}
protected:
enum { N = SkBENCHLOOP(15000) };
virtual const char* onGetName() SK_OVERRIDE {
switch (fType) {
case kAdd_AddType:
@ -564,42 +553,42 @@ protected:
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
switch (fType) {
case kAdd_AddType:
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
int idx = i & (kPathCnt - 1);
SkPath result = fPaths0[idx];
result.addPath(fPaths1[idx]);
}
break;
case kAddTrans_AddType:
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
int idx = i & (kPathCnt - 1);
SkPath result = fPaths0[idx];
result.addPath(fPaths1[idx], 2 * SK_Scalar1, 5 * SK_Scalar1);
}
break;
case kAddMatrix_AddType:
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
int idx = i & (kPathCnt - 1);
SkPath result = fPaths0[idx];
result.addPath(fPaths1[idx], fMatrix);
}
break;
case kPathTo_AddType:
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
int idx = i & (kPathCnt - 1);
SkPath result = fPaths0[idx];
result.pathTo(fPaths1[idx]);
}
break;
case kReverseAdd_AddType:
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
int idx = i & (kPathCnt - 1);
SkPath result = fPaths0[idx];
result.reverseAddPath(fPaths1[idx]);
}
break;
case kReversePathTo_AddType:
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
int idx = i & (kPathCnt - 1);
SkPath result = fPaths0[idx];
result.reversePathTo(fPaths1[idx]);
@ -631,9 +620,6 @@ protected:
SkString fName;
Flags fFlags;
enum {
N = SkBENCHLOOP(100)
};
public:
CirclesBench(void* param, Flags flags) : INHERITED(param), fFlags(flags) {
fName.printf("circles_%s", fFlags & kStroke_Flag ? "stroke" : "fill");
@ -657,7 +643,7 @@ protected:
SkRect r;
for (int i = 0; i < 5000; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkScalar radius = rand.nextUScalar1() * 3;
r.fLeft = rand.nextUScalar1() * 300;
r.fTop = rand.nextUScalar1() * 300;
@ -694,9 +680,6 @@ class ArbRoundRectBench : public SkBenchmark {
protected:
SkString fName;
enum {
N = SkBENCHLOOP(100)
};
public:
ArbRoundRectBench(void* param, bool zeroRad) : INHERITED(param), fZeroRad(zeroRad) {
if (zeroRad) {
@ -757,7 +740,7 @@ protected:
SkRandom rand;
SkRect r;
for (int i = 0; i < 5000; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkPaint paint;
paint.setColor(0xff000000 | rand.nextU());
paint.setAntiAlias(true);
@ -825,7 +808,7 @@ private:
}
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
const SkRect& rect = fQueryRects[i % kQueryRectCnt];
fParity = fParity != fPath.conservativelyContainsRect(rect);
}
@ -852,7 +835,6 @@ private:
}
enum {
N = SkBENCHLOOP(100000),
kQueryRectCnt = 400,
};
static const SkRect kBounds; // bounds for all random query rects
@ -874,9 +856,6 @@ private:
#include "SkGeometry.h"
class ConicBench_Chop5 : public SkBenchmark {
enum {
N = 100000
};
SkConic fRQ;
public:
ConicBench_Chop5(void* param) : INHERITED(param) {
@ -893,7 +872,7 @@ private:
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
SkConic dst[2];
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
fRQ.chopAt(0.5f, dst);
}
}
@ -902,9 +881,6 @@ private:
};
class ConicBench_ChopHalf : public SkBenchmark {
enum {
N = 100000
};
SkConic fRQ;
public:
ConicBench_ChopHalf(void* param) : INHERITED(param) {
@ -921,7 +897,7 @@ private:
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
SkConic dst[2];
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
fRQ.chop(dst);
}
}
@ -954,7 +930,6 @@ public:
protected:
enum {
N = 20000,
CONICS = 100
};
SkConic fConics[CONICS];
@ -974,7 +949,7 @@ protected:
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
SkVector err;
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
for (int j = 0; j < CONICS; ++j) {
fConics[j].computeAsQuadError(&err);
}
@ -995,7 +970,7 @@ protected:
}
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
for (int j = 0; j < CONICS; ++j) {
fConics[j].asQuadTol(SK_ScalarHalf);
}
@ -1016,7 +991,7 @@ protected:
}
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
for (int j = 0; j < CONICS; ++j) {
fConics[j].computeQuadPOW2(SK_ScalarHalf);
}

Просмотреть файл

@ -30,8 +30,6 @@ class PathIterBench : public SkBenchmark {
SkPath fPath;
bool fRaw;
enum { N = SkBENCHLOOP(500) };
public:
PathIterBench(void* param, bool raw) : INHERITED(param) {
fName.printf("pathiter_%s", raw ? "raw" : "consume");
@ -67,7 +65,7 @@ protected:
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
if (fRaw) {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkPath::RawIter iter(fPath);
SkPath::Verb verb;
SkPoint pts[4];
@ -75,7 +73,7 @@ protected:
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { }
}
} else {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkPath::Iter iter(fPath, false);
SkPath::Verb verb;
SkPoint pts[4];

Просмотреть файл

@ -41,8 +41,6 @@ class PathUtilsBench : public SkBenchmark {
SkString fName;
char* bits[H * STRIDE];
enum { N = SkBENCHLOOP(20) };
public:
PathUtilsBench(void* param, Proc proc, const char name[]) : INHERITED(param) {
fProc = proc;
@ -56,7 +54,7 @@ protected:
virtual void onDraw(SkCanvas* canvas) {
for (int i = 0; i < N; ++i){
for (int i = 0; i < this->getLoops(); ++i){
//create a random 16x16 bitmap
fillRandomBits(H * STRIDE, (char*) &bits);

Просмотреть файл

@ -48,7 +48,10 @@ private:
seed, stitchTiles ? &fSize : NULL);
SkPaint paint;
paint.setShader(shader)->unref();
this->drawClippedRect(canvas, x, y, paint);
for (int i = 0; i < this->getLoops(); i++) {
this->drawClippedRect(canvas, x, y, paint);
}
}
typedef SkBenchmark INHERITED;

Просмотреть файл

@ -26,7 +26,6 @@ public:
}
enum {
N = SkBENCHLOOP(200), // number of times to playback the picture
PICTURE_WIDTH = 1000,
PICTURE_HEIGHT = 4000,
TEXT_SIZE = 10
@ -44,16 +43,16 @@ protected:
recordCanvas(pCanvas);
picture.endRecording();
const SkPoint translateDelta = getTranslateDelta();
const SkPoint translateDelta = getTranslateDelta(this->getLoops());
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
picture.draw(canvas);
canvas->translate(translateDelta.fX, translateDelta.fY);
}
}
virtual void recordCanvas(SkCanvas* canvas) = 0;
virtual SkPoint getTranslateDelta() {
virtual SkPoint getTranslateDelta(int N) {
SkIPoint canvasSize = onGetSize();
return SkPoint::Make(SkIntToScalar((PICTURE_WIDTH - canvasSize.fX)/N),
SkIntToScalar((PICTURE_HEIGHT- canvasSize.fY)/N));

Просмотреть файл

@ -24,7 +24,6 @@ public:
}
enum {
N = SkBENCHLOOP(25), // number of times to create the picture
PICTURE_WIDTH = 1000,
PICTURE_HEIGHT = 4000,
};
@ -34,25 +33,18 @@ protected:
}
virtual void onDraw(SkCanvas*) {
int n = (int)(N * this->innerLoopScale());
n = SkMax32(1, n);
SkPicture picture;
for (int i = 0; i < n; i++) {
SkCanvas* pCanvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT);
recordCanvas(pCanvas);
SkPicture picture;
SkCanvas* pCanvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT);
recordCanvas(pCanvas);
// we don't need to draw the picture as the endRecording step will
// do the work of transferring the recorded content into a playback
// object.
picture.endRecording();
}
// we don't need to draw the picture as the endRecording step will
// do the work of transferring the recorded content into a playback
// object.
picture.endRecording();
}
virtual void recordCanvas(SkCanvas* canvas) = 0;
virtual float innerLoopScale() const { return 1; }
SkString fName;
SkScalar fPictureWidth;
@ -72,18 +64,15 @@ public:
DictionaryRecordBench(void* param)
: INHERITED(param, "dictionaries") { }
enum {
M = SkBENCHLOOP(100), // number of elements in each dictionary
};
protected:
virtual void recordCanvas(SkCanvas* canvas) {
const SkPoint translateDelta = getTranslateDelta();
const SkPoint translateDelta = getTranslateDelta(this->getLoops());
for (int i = 0; i < M; i++) {
for (int i = 0; i < this->getLoops(); i++) {
SkColor color = SK_ColorYELLOW + (i % 255);
SkIRect rect = SkIRect::MakeWH(i,i);
SkIRect rect = SkIRect::MakeWH(i % PICTURE_WIDTH, i % PICTURE_HEIGHT);
canvas->save();
@ -119,7 +108,7 @@ protected:
}
}
SkPoint getTranslateDelta() {
SkPoint getTranslateDelta(int M) {
SkIPoint canvasSize = onGetSize();
return SkPoint::Make(SkIntToScalar((PICTURE_WIDTH - canvasSize.fX)/M),
SkIntToScalar((PICTURE_HEIGHT- canvasSize.fY)/M));
@ -137,14 +126,10 @@ public:
UniquePaintDictionaryRecordBench(void* param)
: INHERITED(param, "unique_paint_dictionary") { }
enum {
M = SkBENCHLOOP(15000), // number of unique paint objects
};
protected:
virtual float innerLoopScale() const SK_OVERRIDE { return 0.1f; }
virtual void recordCanvas(SkCanvas* canvas) {
SkRandom rand;
for (int i = 0; i < M; i++) {
for (int i = 0; i < this->getLoops(); i++) {
SkPaint paint;
paint.setColor(rand.nextU());
canvas->drawPaint(paint);
@ -174,14 +159,12 @@ public:
}
enum {
ObjCount = 100, // number of unique paint objects
M = SkBENCHLOOP(50000), // number of draw iterations
ObjCount = 100, // number of unique paint objects
};
protected:
virtual float innerLoopScale() const SK_OVERRIDE { return 0.1f; }
virtual void recordCanvas(SkCanvas* canvas) {
for (int i = 0; i < M; i++) {
for (int i = 0; i < this->getLoops(); i++) {
canvas->drawPaint(fPaint[i % ObjCount]);
}
}

Просмотреть файл

@ -46,8 +46,7 @@ protected:
bmp2.setConfig(SkBitmap::kARGB_8888_Config, size.width(),
size.height());
static const int kLoopCount = SkBENCHLOOP(10);
for (int loop = 0; loop < kLoopCount; ++loop) {
for (int loop = 0; loop < this->getLoops(); ++loop) {
// Unpremul -> Premul
canvas->writePixels(bmp1, 0, 0, fUnPremulConfig);
// Premul -> Unpremul

Просмотреть файл

@ -16,7 +16,6 @@
static const int GENERATE_EXTENTS = 1000;
static const int NUM_BUILD_RECTS = 500;
static const int NUM_QUERY_RECTS = 5000;
static const int NUM_QUERIES = 1000;
static const int GRID_WIDTH = 100;
typedef SkIRect (*MakeRectProc)(SkRandom&, int, int);
@ -47,7 +46,7 @@ protected:
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkRandom rand;
for (int i = 0; i < SkBENCHLOOP(100); ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
for (int j = 0; j < NUM_BUILD_RECTS; ++j) {
fTree->insert(reinterpret_cast<void*>(j), fProc(rand, j, NUM_BUILD_RECTS),
fBulkLoad);
@ -98,16 +97,17 @@ protected:
}
virtual void onPreDraw() SK_OVERRIDE {
SkRandom rand;
for (int j = 0; j < SkBENCHLOOP(NUM_QUERY_RECTS); ++j) {
fTree->insert(reinterpret_cast<void*>(j), fProc(rand, j,
SkBENCHLOOP(NUM_QUERY_RECTS)), fBulkLoad);
for (int j = 0; j < NUM_QUERY_RECTS; ++j) {
fTree->insert(reinterpret_cast<void*>(j),
fProc(rand, j, NUM_QUERY_RECTS),
fBulkLoad);
}
fTree->flushDeferredInserts();
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkRandom rand;
for (int i = 0; i < SkBENCHLOOP(NUM_QUERIES); ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkTDArray<void*> hits;
SkIRect query;
switch(fQuery) {

Просмотреть файл

@ -45,9 +45,11 @@ protected:
bitmap.setConfig(SkBitmap::kARGB_8888_Config, kWindowSize, kWindowSize);
for (int x = 0; x < kNumStepsX; ++x) {
for (int y = 0; y < kNumStepsY; ++y) {
canvas->readPixels(&bitmap, x * offX, y * offY);
for (int i = 0; i < this->getLoops(); i++) {
for (int x = 0; x < kNumStepsX; ++x) {
for (int y = 0; y < kNumStepsY; ++y) {
canvas->readPixels(&bitmap, x * offX, y * offY);
}
}
}
}

Просмотреть файл

@ -7,10 +7,13 @@
*/
#include "SkBenchmark.h"
#include "SkCanvas.h"
#include "SkCommandLineFlags.h"
#include "SkPaint.h"
#include "SkRandom.h"
#include "SkString.h"
#include "SkShader.h"
#include "SkString.h"
DEFINE_double(strokeWidth, -1.0, "If set, use this stroke width in RectBench.");
class RectBench : public SkBenchmark {
public:
@ -18,7 +21,7 @@ public:
enum {
W = 640,
H = 480,
N = SkBENCHLOOP(300)
N = 300,
};
SkRect fRects[N];
SkColor fColors[N];
@ -66,10 +69,10 @@ protected:
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SkIntToScalar(fStroke));
}
for (int i = 0; i < N; i++) {
paint.setColor(fColors[i]);
for (int i = 0; i < this->getLoops(); i++) {
paint.setColor(fColors[i % N]);
this->setupPaint(&paint);
this->drawThisRect(canvas, fRects[i], paint);
this->drawThisRect(canvas, fRects[i % N], paint);
}
}
private:
@ -144,19 +147,21 @@ protected:
};
size_t sizes = SK_ARRAY_COUNT(gSizes);
if (this->hasStrokeWidth()) {
gSizes[0] = this->getStrokeWidth();
if (FLAGS_strokeWidth >= 0) {
gSizes[0] = FLAGS_strokeWidth;
sizes = 1;
}
SkPaint paint;
paint.setStrokeCap(SkPaint::kRound_Cap);
for (size_t i = 0; i < sizes; i++) {
paint.setStrokeWidth(gSizes[i]);
this->setupPaint(&paint);
canvas->drawPoints(fMode, N * 2, SkTCast<SkPoint*>(fRects), paint);
paint.setColor(fColors[i]);
for (int loop = 0; loop < this->getLoops(); loop++) {
for (size_t i = 0; i < sizes; i++) {
paint.setStrokeWidth(gSizes[i]);
this->setupPaint(&paint);
canvas->drawPoints(fMode, N * 2, SkTCast<SkPoint*>(fRects), paint);
paint.setColor(fColors[i % N]);
}
}
}
virtual const char* onGetName() { return fName; }
@ -190,21 +195,23 @@ protected:
SkRect r = { -kHalfRectSize, -kHalfRectSize, kHalfRectSize, kHalfRectSize };
int rot = 0;
// Draw small aa rects in a grid across the screen
for (SkScalar y = kHalfRectSize+SK_Scalar1; y < H; y += 2*kHalfRectSize+2) {
for (SkScalar x = kHalfRectSize+SK_Scalar1; x < W; x += 2*kHalfRectSize+2) {
canvas->save();
canvas->translate(x, y);
for (int i = 0; i < this->getLoops(); i++) {
// Draw small aa rects in a grid across the screen
for (SkScalar y = kHalfRectSize+SK_Scalar1; y < H; y += 2*kHalfRectSize+2) {
for (SkScalar x = kHalfRectSize+SK_Scalar1; x < W; x += 2*kHalfRectSize+2) {
canvas->save();
canvas->translate(x, y);
if (fRotate) {
SkMatrix rotate;
rotate.setRotate(SkIntToScalar(rot));
canvas->concat(rotate);
rot += 10;
if (fRotate) {
SkMatrix rotate;
rotate.setRotate(SkIntToScalar(rot));
canvas->concat(rotate);
rot += 10;
}
canvas->drawRect(r, paint);
canvas->restore();
}
canvas->drawRect(r, paint);
canvas->restore();
}
}
@ -242,8 +249,8 @@ protected:
};
size_t sizes = SK_ARRAY_COUNT(gSizes);
if (this->hasStrokeWidth()) {
gSizes[0] = this->getStrokeWidth();
if (FLAGS_strokeWidth >= 0) {
gSizes[0] = FLAGS_strokeWidth;
sizes = 1;
}
SkRandom rand;
@ -262,29 +269,31 @@ protected:
SkShader::kClamp_TileMode);
paint.setShader(s)->unref();
}
for (size_t i = 0; i < sizes; i++) {
switch (_type) {
case kMaskOpaque:
color = fColors[i];
alpha = 0xFF;
break;
case kMaskBlack:
alpha = 0xFF;
color = 0xFF000000;
break;
case kMaskColor:
color = fColors[i];
alpha = rand.nextU() & 255;
break;
case KMaskShader:
break;
}
paint.setStrokeWidth(gSizes[i]);
this->setupPaint(&paint);
paint.setColor(color);
paint.setAlpha(alpha);
canvas->drawPoints(fMode, N * 2, SkTCast<SkPoint*>(fRects), paint);
}
for (int loop = 0; loop < this->getLoops(); loop++) {
for (size_t i = 0; i < sizes; i++) {
switch (_type) {
case kMaskOpaque:
color = fColors[i];
alpha = 0xFF;
break;
case kMaskBlack:
alpha = 0xFF;
color = 0xFF000000;
break;
case kMaskColor:
color = fColors[i];
alpha = rand.nextU() & 255;
break;
case KMaskShader:
break;
}
paint.setStrokeWidth(gSizes[i]);
this->setupPaint(&paint);
paint.setColor(color);
paint.setAlpha(alpha);
canvas->drawPoints(fMode, N * 2, SkTCast<SkPoint*>(fRects), paint);
}
}
}
virtual const char* onGetName() { return fName; }
private:

Просмотреть файл

@ -27,7 +27,7 @@ protected:
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkRandom Random;
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
SkScalar blurSigma = Random.nextRangeScalar(1.5f, 25.0f);
SkScalar size = Random.nextRangeScalar(20*blurSigma, 50*blurSigma);
@ -70,8 +70,6 @@ private:
H = 480,
};
enum { N = SkBENCHLOOP(100) };
SkLayerDrawLooper* createLooper(SkScalar xOff, SkScalar sigma) {
SkLayerDrawLooper* looper = new SkLayerDrawLooper;

Просмотреть файл

@ -11,8 +11,7 @@
#include <memory>
enum {
N = SkBENCHLOOP(100000),
M = SkBENCHLOOP(2)
M = 2
};
class RefCntBench_Stack : public SkBenchmark {
@ -26,7 +25,7 @@ protected:
}
virtual void onDraw(SkCanvas*) {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkRefCnt ref;
for (int j = 0; j < M; ++j) {
ref.ref();
@ -64,7 +63,7 @@ protected:
virtual void onDraw(SkCanvas*) {
char memory[sizeof(PlacedRefCnt)];
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
PlacedRefCnt* ref = new (memory) PlacedRefCnt();
for (int j = 0; j < M; ++j) {
ref->ref();
@ -89,7 +88,7 @@ protected:
}
virtual void onDraw(SkCanvas*) {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkRefCnt* ref = new SkRefCnt();
for (int j = 0; j < M; ++j) {
ref->ref();
@ -116,7 +115,7 @@ protected:
}
virtual void onDraw(SkCanvas*) {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkWeakRefCnt ref;
for (int j = 0; j < M; ++j) {
ref.ref();
@ -147,7 +146,7 @@ protected:
virtual void onDraw(SkCanvas*) {
char memory[sizeof(PlacedWeakRefCnt)];
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
PlacedWeakRefCnt* ref = new (memory) PlacedWeakRefCnt();
for (int j = 0; j < M; ++j) {
ref->ref();
@ -172,7 +171,7 @@ protected:
}
virtual void onDraw(SkCanvas*) {
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkWeakRefCnt* ref = new SkWeakRefCnt();
for (int j = 0; j < M; ++j) {
ref->ref();

Просмотреть файл

@ -74,12 +74,10 @@ public:
SkRegion fA, fB;
Proc fProc;
SkString fName;
int fLoopMul;
enum {
W = 1024,
H = 768,
N = SkBENCHLOOP(2000)
};
SkIRect randrect(SkRandom& rand) {
@ -90,10 +88,9 @@ public:
return SkIRect::MakeXYWH(x, y, w >> 1, h >> 1);
}
RegionBench(void* param, int count, Proc proc, const char name[], int mul = 1) : INHERITED(param) {
RegionBench(void* param, int count, Proc proc, const char name[]) : INHERITED(param) {
fProc = proc;
fName.printf("region_%s_%d", name, count);
fLoopMul = mul;
SkRandom rand;
for (int i = 0; i < count; i++) {
@ -108,8 +105,7 @@ protected:
virtual void onDraw(SkCanvas* canvas) {
Proc proc = fProc;
int n = fLoopMul * N;
for (int i = 0; i < n; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
proc(fA, fB);
}
}
@ -125,9 +121,9 @@ static SkBenchmark* gF1(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, sec
static SkBenchmark* gF2(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, diff_proc, "difference")); }
static SkBenchmark* gF3(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, diffrect_proc, "differencerect")); }
static SkBenchmark* gF4(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, diffrectbig_proc, "differencerectbig")); }
static SkBenchmark* gF5(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, containsrect_proc, "containsrect", 100)); }
static SkBenchmark* gF6(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, sectsrgn_proc, "intersectsrgn", 10)); }
static SkBenchmark* gF7(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, sectsrect_proc, "intersectsrect", 200)); }
static SkBenchmark* gF5(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, containsrect_proc, "containsrect")); }
static SkBenchmark* gF6(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, sectsrgn_proc, "intersectsrgn")); }
static SkBenchmark* gF7(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, sectsrect_proc, "intersectsrect")); }
static SkBenchmark* gF8(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, containsxy_proc, "containsxy")); }
static BenchRegistry gR0(gF0);

Просмотреть файл

@ -26,7 +26,6 @@ public:
W = 200,
H = 200,
COUNT = 10,
N = SkBENCHLOOP(20000)
};
SkIRect randrect(SkRandom& rand, int i) {
@ -54,7 +53,7 @@ protected:
virtual void onDraw(SkCanvas*) {
Proc proc = fProc;
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
proc(fA, fB);
}
}

Просмотреть файл

@ -89,7 +89,6 @@ class RepeatTileBench : public SkBenchmark {
SkBitmap fBitmap;
bool fIsOpaque;
SkBitmap::Config fConfig;
enum { N = SkBENCHLOOP(20) };
public:
RepeatTileBench(void* param, SkBitmap::Config c, bool isOpaque = false) : INHERITED(param) {
const int w = 50;
@ -135,7 +134,7 @@ protected:
SkPaint paint(fPaint);
this->setupPaint(&paint);
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
canvas->drawPaint(paint);
}
}

Просмотреть файл

@ -13,7 +13,6 @@
class ScalarBench : public SkBenchmark {
SkString fName;
enum { N = 100000 };
public:
ScalarBench(void* param, const char name[]) : INHERITED(param) {
fName.printf("scalar_%s", name);
@ -30,8 +29,7 @@ protected:
}
virtual void onDraw(SkCanvas* canvas) {
int n = SkBENCHLOOP(N * this->mulLoopCount());
for (int i = 0; i < n; i++) {
for (int i = 0; i < this->getLoops(); i++) {
this->performTest();
}
}
@ -135,7 +133,6 @@ private:
class RectBoundsBench : public SkBenchmark {
enum {
PTS = 100,
N = SkBENCHLOOP(10000)
};
SkPoint fPts[PTS];
@ -156,7 +153,7 @@ protected:
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkRect r;
for (int i = 0; i < N; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
r.set(fPts, PTS);
}
}

Просмотреть файл

@ -37,7 +37,6 @@ class ShaderMaskBench : public SkBenchmark {
SkString fText;
SkString fName;
FontQuality fFQ;
enum { N = SkBENCHLOOP(500) };
public:
ShaderMaskBench(void* param, bool isOpaque, FontQuality fq) : INHERITED(param) {
fFQ = fq;
@ -72,14 +71,14 @@ protected:
const SkScalar y0 = SkIntToScalar(-10);
paint.setTextSize(SkIntToScalar(12));
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
SkScalar x = x0 + rand.nextUScalar1() * dim.fX;
SkScalar y = y0 + rand.nextUScalar1() * dim.fY;
canvas->drawText(fText.c_str(), fText.size(), x, y, paint);
}
paint.setTextSize(SkIntToScalar(48));
for (int i = 0; i < N/4; i++) {
for (int i = 0; i < this->getLoops() / 4 ; i++) {
SkScalar x = x0 + rand.nextUScalar1() * dim.fX;
SkScalar y = y0 + rand.nextUScalar1() * dim.fY;
canvas->drawText(fText.c_str(), fText.size(), x, y, paint);

Просмотреть файл

@ -9,18 +9,19 @@
#include "SkPaint.h"
#include "SkParse.h"
const char* SkTriState::Name[] = { "default", "true", "false" };
SK_DEFINE_INST_COUNT(SkBenchmark)
template BenchRegistry* BenchRegistry::gHead;
SkBenchmark::SkBenchmark(void* defineDict) {
fDict = reinterpret_cast<const SkTDict<const char*>*>(defineDict);
SkBenchmark::SkBenchmark(void* /*ignored*/) {
fForceAlpha = 0xFF;
fForceAA = true;
fDither = SkTriState::kDefault;
fHasStrokeWidth = false;
fIsRendering = true;
fOrMask = fClearMask = 0;
fLoops = 1;
}
const char* SkBenchmark::getName() {
@ -55,33 +56,6 @@ void SkBenchmark::setupPaint(SkPaint* paint) {
}
}
const char* SkBenchmark::findDefine(const char* key) const {
if (fDict) {
const char* value;
if (fDict->find(key, &value)) {
return value;
}
}
return NULL;
}
bool SkBenchmark::findDefine32(const char* key, int32_t* value) const {
const char* valueStr = this->findDefine(key);
if (valueStr) {
SkParse::FindS32(valueStr, value);
return true;
}
return false;
}
bool SkBenchmark::findDefineScalar(const char* key, SkScalar* value) const {
const char* valueStr = this->findDefine(key);
if (valueStr) {
SkParse::FindScalar(valueStr, value);
return true;
}
return false;
}
///////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -10,7 +10,6 @@
#include "SkRefCnt.h"
#include "SkPoint.h"
#include "SkTDict.h"
#include "SkTRegistry.h"
#define DEF_BENCH(code) \
@ -27,12 +26,6 @@ static BenchRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_));
*/
#ifdef SK_DEBUG
#define SkBENCHLOOP(n) 1
#else
#define SkBENCHLOOP(n) n
#endif
class SkCanvas;
class SkPaint;
@ -43,6 +36,7 @@ public:
kTrue,
kFalse
};
static const char* Name[];
};
class SkBenchmark : public SkRefCnt {
@ -82,19 +76,6 @@ public:
fDither = state;
}
void setStrokeWidth(SkScalar width) {
strokeWidth = width;
fHasStrokeWidth = true;
}
SkScalar getStrokeWidth() {
return strokeWidth;
}
bool hasStrokeWidth() {
return fHasStrokeWidth;
}
/** If true; the benchmark does rendering; if false, the benchmark
doesn't, and so need not be re-run in every different rendering
mode. */
@ -102,10 +83,6 @@ public:
return fIsRendering;
}
const char* findDefine(const char* key) const;
bool findDefine32(const char* key, int32_t* value) const;
bool findDefineScalar(const char* key, SkScalar* value) const;
/** Assign masks for paint-flags. These will be applied when setupPaint()
* is called.
*
@ -120,7 +97,14 @@ public:
fClearMask = clearMask;
}
float getDurationScale() { return this->onGetDurationScale(); }
// The bench framework calls this to control the runtime of a bench.
void setLoops(int loops) {
fLoops = loops;
}
// Each bench should do its main work in a loop like this:
// for (int i = 0; i < this->getLoops(); i++) { <work here> }
int getLoops() const { return fLoops; }
protected:
virtual void setupPaint(SkPaint* paint);
@ -129,27 +113,18 @@ protected:
virtual void onPreDraw() {}
virtual void onDraw(SkCanvas*) = 0;
virtual void onPostDraw() {}
// the caller will scale the computed duration by this value. It allows a
// slow bench to run fewer inner loops, but return the corresponding scale
// so that its reported duration can be compared against other benches.
// e.g.
// if I run 10x slower, I can run 1/10 the number of inner-loops, but
// return 10.0 for my durationScale, so I "report" the honest duration.
virtual float onGetDurationScale() { return 1; }
virtual SkIPoint onGetSize();
/// Defaults to true.
bool fIsRendering;
private:
const SkTDict<const char*>* fDict;
int fForceAlpha;
bool fForceAA;
bool fForceFilter;
SkTriState::State fDither;
bool fHasStrokeWidth;
SkScalar strokeWidth;
uint32_t fOrMask, fClearMask;
int fLoops;
typedef SkRefCnt INHERITED;
};

Просмотреть файл

@ -121,8 +121,7 @@ protected:
}
virtual void onDraw(SkCanvas*) {
int n = SkBENCHLOOP(200);
for (int i = 0; i < n; i++) {
for (int i = 0; i < this->getLoops(); i++) {
memcpy(fSorted, fUnsorted, fCount * sizeof(int));
fSortProc(fSorted, fCount);
#ifdef SK_DEBUG

Просмотреть файл

@ -58,7 +58,6 @@ class StrokeRRectBench : public SkBenchmark {
SkPaint::Join fJoin;
RRectRec fRec;
DrawProc fProc;
enum { N = SkBENCHLOOP(500) };
public:
StrokeRRectBench(void* param, SkPaint::Join j, DrawProc proc) : SkBenchmark(param) {
static const char* gJoinName[] = {
@ -85,7 +84,7 @@ protected:
fRec.fPaint.setStyle(SkPaint::kStroke_Style);
fRec.fPaint.setStrokeJoin(fJoin);
fRec.fPaint.setStrokeWidth(5);
fProc(&fRec, N);
fProc(&fRec, this->getLoops());
}
private:

Просмотреть файл

@ -25,8 +25,6 @@ static const SkScalar kCellHeight = SkIntToScalar(10);
// This trio of drawRects is then repeat for the next cell.
class TableBench : public SkBenchmark {
public:
static const int kNumIterations = SkBENCHLOOP(10);
static const int kNumRows = 48;
static const int kNumCols = 32;
@ -40,14 +38,13 @@ protected:
}
virtual void onDraw(SkCanvas* canvas) {
SkPaint cellPaint;
cellPaint.setColor(0xFFFFFFF);
SkPaint borderPaint;
borderPaint.setColor(0xFFCCCCCC);
for (int i = 0; i < kNumIterations; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
for (int row = 0; row < kNumRows; ++row) {
for (int col = 0; col < kNumCols; ++col) {
SkRect cell = SkRect::MakeLTRB(col * kCellWidth,

Просмотреть файл

@ -45,7 +45,6 @@ class TextBench : public SkBenchmark {
FontQuality fFQ;
bool fDoPos;
SkPoint* fPos;
enum { N = SkBENCHLOOP(800) };
public:
TextBench(void* param, const char text[], int ps,
SkColor color, FontQuality fq, bool doPos = false) : INHERITED(param) {
@ -112,7 +111,7 @@ protected:
canvas->translate(SK_Scalar1, SK_Scalar1);
}
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
if (fDoPos) {
canvas->drawPosText(fText.c_str(), fText.size(), fPos, paint);
} else {

Просмотреть файл

@ -34,7 +34,6 @@ class ConstXTileBench : public SkBenchmark {
bool fDoFilter;
bool fDoTrans;
bool fDoScale;
enum { N = SkBENCHLOOP(20) };
static const int kWidth = 1;
static const int kHeight = 300;
@ -106,7 +105,7 @@ protected:
SkPaint bgPaint;
bgPaint.setColor(SK_ColorWHITE);
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
if (fDoTrans) {
canvas->drawRect(r, bgPaint);
}

Просмотреть файл

@ -26,7 +26,6 @@ class VertBench : public SkBenchmark {
COL = 20,
PTS = (ROW + 1) * (COL + 1),
IDX = ROW * COL * 6,
N = SkBENCHLOOP(10)
};
SkPoint fPts[PTS];
@ -82,7 +81,7 @@ protected:
SkPaint paint;
this->setupPaint(&paint);
for (int i = 0; i < N; i++) {
for (int i = 0; i < this->getLoops(); i++) {
canvas->drawVertices(SkCanvas::kTriangles_VertexMode, PTS,
fPts, NULL, fColors, NULL, fIdx, IDX, paint);
}

Просмотреть файл

@ -56,14 +56,12 @@ protected:
bmp.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height());
canvas->readPixels(&bmp, 0, 0);
for (int loop = 0; loop < kLoopCount; ++loop) {
for (int loop = 0; loop < this->getLoops(); ++loop) {
canvas->writePixels(bmp, 0, 0, fConfig);
}
}
private:
static const int kLoopCount = SkBENCHLOOP(50);
SkCanvas::Config8888 fConfig;
SkString fName;

Просмотреть файл

@ -25,7 +25,7 @@ protected:
static const char gStr[] = "abcdefghimjklmnopqrstuvwxyz";
static const size_t gLen = strlen(gStr);
SkWriter32 writer(256 * 4);
for (int i = 0; i < SkBENCHLOOP(800); i++) {
for (int i = 0; i < this->getLoops(); i++) {
for (size_t j = 0; j <= gLen; j++) {
writer.writeString(gStr, j);
}

Просмотреть файл

@ -36,7 +36,7 @@ protected:
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkISize size = canvas->getDeviceSize();
SkRandom random;
for (int i = 0; i < kNumRects; ++i) {
for (int i = 0; i < this->getLoops(); ++i) {
SkPaint paint;
paint.setXfermode(fXfermode.get());
paint.setColor(random.nextU());
@ -54,7 +54,6 @@ protected:
private:
enum {
kNumRects = SkBENCHLOOP(75),
kMinSize = 50,
kMaxSize = 100,
};

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -74,8 +74,6 @@
'../bench/SkBenchLogger.h',
'../bench/SkBenchLogger.cpp',
'../bench/TimerData.h',
'../bench/TimerData.cpp',
],
}

Просмотреть файл

@ -17,9 +17,9 @@
#include "SkTArray.h"
#include "TimerData.h"
static const int kNumNormalRecordings = SkBENCHLOOP(10);
static const int kNumRTreeRecordings = SkBENCHLOOP(10);
static const int kNumPlaybacks = SkBENCHLOOP(1);
static const int kNumNormalRecordings = 10;
static const int kNumRTreeRecordings = 10;
static const int kNumPlaybacks = 1;
static const size_t kNumBaseBenchmarks = 3;
static const size_t kNumTileSizes = 3;
static const size_t kNumBbhPlaybackBenchmarks = 3;