2012-09-05 18:36:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2012 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 "SkCanvas.h"
|
|
|
|
#include "SkRTree.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
|
|
|
// confine rectangles to a smallish area, so queries generally hit something, and overlap occurs:
|
|
|
|
static const int GENERATE_EXTENTS = 1000;
|
|
|
|
static const int NUM_BUILD_RECTS = 500;
|
|
|
|
static const int NUM_QUERY_RECTS = 5000;
|
2013-08-30 17:27:47 +00:00
|
|
|
static const int GRID_WIDTH = 100;
|
2012-09-05 18:36:17 +00:00
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
typedef SkIRect (*MakeRectProc)(SkRandom&, int, int);
|
2012-09-05 18:36:17 +00:00
|
|
|
|
|
|
|
// Time how long it takes to build an R-Tree either bulk-loaded or not
|
|
|
|
class BBoxBuildBench : public SkBenchmark {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
BBoxBuildBench(const char* name, MakeRectProc proc, bool bulkLoad,
|
2012-09-05 18:36:17 +00:00
|
|
|
SkBBoxHierarchy* tree)
|
2013-09-13 19:52:27 +00:00
|
|
|
: fTree(tree)
|
2012-09-05 18:36:17 +00:00
|
|
|
, fProc(proc)
|
2012-09-06 13:38:53 +00:00
|
|
|
, fBulkLoad(bulkLoad) {
|
|
|
|
fName.append("rtree_");
|
|
|
|
fName.append(name);
|
|
|
|
fName.append("_build");
|
2012-09-05 18:36:17 +00:00
|
|
|
if (fBulkLoad) {
|
2012-09-06 13:38:53 +00:00
|
|
|
fName.append("_bulk");
|
2012-09-05 18:36:17 +00:00
|
|
|
}
|
2012-09-06 13:38:53 +00:00
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
|
|
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
2012-09-11 11:54:07 +00:00
|
|
|
virtual ~BBoxBuildBench() {
|
2012-09-11 15:41:50 +00:00
|
|
|
fTree->unref();
|
2012-09-11 11:54:07 +00:00
|
|
|
}
|
2012-09-06 13:38:53 +00:00
|
|
|
protected:
|
When skia run bench cases to test performance, it will run constructors for all cases one by one, then getName to skip unnecessary cases according to command line parameters, so these constructors should be lightweight enough to avoid redundant computing. Unfortunately, some constructors contain intensive computing/rendering. They are very heavy, maybe much heavier than need-to-run bench case itself. And these redundant computation will be run every time you run bench, even you just test a single simple case. Moreover, it will mislead the real hotspot/bottleneck of the case itself.
For example, run a lightweight case, say, region_intersectsrgn_16, the hot spots are gles operation, SuperBlitter, SkRTree... introduced by irrelevant cases' constructors. These redundant computation will mislead performance tuning.
So we can move these intensive computation to onPreDraw() of these case. They will be executed only if this case should be run.
R=reed@google.com, robertphillips@google.com, humper@google.com, tomhudson@chromium.org
Author: yunchao.he@intel.com
Review URL: https://chromiumcodereview.appspot.com/20997003
git-svn-id: http://skia.googlecode.com/svn/trunk@10486 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-08-01 15:58:07 +00:00
|
|
|
virtual const char* onGetName() SK_OVERRIDE {
|
2012-09-06 13:38:53 +00:00
|
|
|
return fName.c_str();
|
2012-09-05 18:36:17 +00:00
|
|
|
}
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-09-05 18:36:17 +00:00
|
|
|
for (int j = 0; j < NUM_BUILD_RECTS; ++j) {
|
|
|
|
fTree->insert(reinterpret_cast<void*>(j), fProc(rand, j, NUM_BUILD_RECTS),
|
|
|
|
fBulkLoad);
|
|
|
|
}
|
|
|
|
fTree->flushDeferredInserts();
|
|
|
|
fTree->clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkBBoxHierarchy* fTree;
|
|
|
|
MakeRectProc fProc;
|
2012-09-06 13:38:53 +00:00
|
|
|
SkString fName;
|
2012-09-05 18:36:17 +00:00
|
|
|
bool fBulkLoad;
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Time how long it takes to perform queries on an R-Tree, bulk-loaded or not
|
|
|
|
class BBoxQueryBench : public SkBenchmark {
|
|
|
|
public:
|
|
|
|
enum QueryType {
|
|
|
|
kSmall_QueryType, // small queries
|
|
|
|
kLarge_QueryType, // large queries
|
|
|
|
kRandom_QueryType,// randomly sized queries
|
|
|
|
kFull_QueryType // queries that cover everything
|
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
BBoxQueryBench(const char* name, MakeRectProc proc, bool bulkLoad,
|
2012-09-05 18:36:17 +00:00
|
|
|
QueryType q, SkBBoxHierarchy* tree)
|
2013-09-13 19:52:27 +00:00
|
|
|
: fTree(tree)
|
2012-09-05 18:36:17 +00:00
|
|
|
, fProc(proc)
|
|
|
|
, fBulkLoad(bulkLoad)
|
|
|
|
, fQuery(q) {
|
2012-09-06 13:38:53 +00:00
|
|
|
fName.append("rtree_");
|
|
|
|
fName.append(name);
|
|
|
|
fName.append("_query");
|
|
|
|
if (fBulkLoad) {
|
|
|
|
fName.append("_bulk");
|
|
|
|
}
|
2012-09-05 18:36:17 +00:00
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
|
|
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
2012-09-11 11:54:07 +00:00
|
|
|
virtual ~BBoxQueryBench() {
|
2012-09-11 15:41:50 +00:00
|
|
|
fTree->unref();
|
2012-09-11 11:54:07 +00:00
|
|
|
}
|
2012-09-05 18:36:17 +00:00
|
|
|
protected:
|
When skia run bench cases to test performance, it will run constructors for all cases one by one, then getName to skip unnecessary cases according to command line parameters, so these constructors should be lightweight enough to avoid redundant computing. Unfortunately, some constructors contain intensive computing/rendering. They are very heavy, maybe much heavier than need-to-run bench case itself. And these redundant computation will be run every time you run bench, even you just test a single simple case. Moreover, it will mislead the real hotspot/bottleneck of the case itself.
For example, run a lightweight case, say, region_intersectsrgn_16, the hot spots are gles operation, SuperBlitter, SkRTree... introduced by irrelevant cases' constructors. These redundant computation will mislead performance tuning.
So we can move these intensive computation to onPreDraw() of these case. They will be executed only if this case should be run.
R=reed@google.com, robertphillips@google.com, humper@google.com, tomhudson@chromium.org
Author: yunchao.he@intel.com
Review URL: https://chromiumcodereview.appspot.com/20997003
git-svn-id: http://skia.googlecode.com/svn/trunk@10486 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-08-01 15:58:07 +00:00
|
|
|
virtual const char* onGetName() SK_OVERRIDE {
|
2012-09-06 13:38:53 +00:00
|
|
|
return fName.c_str();
|
2012-09-05 18:36:17 +00:00
|
|
|
}
|
When skia run bench cases to test performance, it will run constructors for all cases one by one, then getName to skip unnecessary cases according to command line parameters, so these constructors should be lightweight enough to avoid redundant computing. Unfortunately, some constructors contain intensive computing/rendering. They are very heavy, maybe much heavier than need-to-run bench case itself. And these redundant computation will be run every time you run bench, even you just test a single simple case. Moreover, it will mislead the real hotspot/bottleneck of the case itself.
For example, run a lightweight case, say, region_intersectsrgn_16, the hot spots are gles operation, SuperBlitter, SkRTree... introduced by irrelevant cases' constructors. These redundant computation will mislead performance tuning.
So we can move these intensive computation to onPreDraw() of these case. They will be executed only if this case should be run.
R=reed@google.com, robertphillips@google.com, humper@google.com, tomhudson@chromium.org
Author: yunchao.he@intel.com
Review URL: https://chromiumcodereview.appspot.com/20997003
git-svn-id: http://skia.googlecode.com/svn/trunk@10486 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-08-01 15:58:07 +00:00
|
|
|
virtual void onPreDraw() SK_OVERRIDE {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-09-10 19:23:38 +00:00
|
|
|
for (int j = 0; j < NUM_QUERY_RECTS; ++j) {
|
|
|
|
fTree->insert(reinterpret_cast<void*>(j),
|
|
|
|
fProc(rand, j, NUM_QUERY_RECTS),
|
|
|
|
fBulkLoad);
|
When skia run bench cases to test performance, it will run constructors for all cases one by one, then getName to skip unnecessary cases according to command line parameters, so these constructors should be lightweight enough to avoid redundant computing. Unfortunately, some constructors contain intensive computing/rendering. They are very heavy, maybe much heavier than need-to-run bench case itself. And these redundant computation will be run every time you run bench, even you just test a single simple case. Moreover, it will mislead the real hotspot/bottleneck of the case itself.
For example, run a lightweight case, say, region_intersectsrgn_16, the hot spots are gles operation, SuperBlitter, SkRTree... introduced by irrelevant cases' constructors. These redundant computation will mislead performance tuning.
So we can move these intensive computation to onPreDraw() of these case. They will be executed only if this case should be run.
R=reed@google.com, robertphillips@google.com, humper@google.com, tomhudson@chromium.org
Author: yunchao.he@intel.com
Review URL: https://chromiumcodereview.appspot.com/20997003
git-svn-id: http://skia.googlecode.com/svn/trunk@10486 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-08-01 15:58:07 +00:00
|
|
|
}
|
|
|
|
fTree->flushDeferredInserts();
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-09-05 18:36:17 +00:00
|
|
|
SkTDArray<void*> hits;
|
|
|
|
SkIRect query;
|
|
|
|
switch(fQuery) {
|
|
|
|
case kSmall_QueryType:
|
|
|
|
query.fLeft = rand.nextU() % GENERATE_EXTENTS;
|
|
|
|
query.fTop = rand.nextU() % GENERATE_EXTENTS;
|
|
|
|
query.fRight = query.fLeft + (GENERATE_EXTENTS / 20);
|
|
|
|
query.fBottom = query.fTop + (GENERATE_EXTENTS / 20);
|
|
|
|
break;
|
|
|
|
case kLarge_QueryType:
|
|
|
|
query.fLeft = rand.nextU() % GENERATE_EXTENTS;
|
|
|
|
query.fTop = rand.nextU() % GENERATE_EXTENTS;
|
|
|
|
query.fRight = query.fLeft + (GENERATE_EXTENTS / 2);
|
|
|
|
query.fBottom = query.fTop + (GENERATE_EXTENTS / 2);
|
|
|
|
break;
|
|
|
|
case kFull_QueryType:
|
|
|
|
query.fLeft = -GENERATE_EXTENTS;
|
|
|
|
query.fTop = -GENERATE_EXTENTS;
|
|
|
|
query.fRight = 2 * GENERATE_EXTENTS;
|
|
|
|
query.fBottom = 2 * GENERATE_EXTENTS;
|
|
|
|
break;
|
|
|
|
default: // fallthrough
|
|
|
|
case kRandom_QueryType:
|
|
|
|
query.fLeft = rand.nextU() % GENERATE_EXTENTS;
|
|
|
|
query.fTop = rand.nextU() % GENERATE_EXTENTS;
|
|
|
|
query.fRight = query.fLeft + 1 + rand.nextU() % (GENERATE_EXTENTS / 2);
|
|
|
|
query.fBottom = query.fTop + 1 + rand.nextU() % (GENERATE_EXTENTS / 2);
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
fTree->search(query, &hits);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkBBoxHierarchy* fTree;
|
|
|
|
MakeRectProc fProc;
|
2012-09-06 13:38:53 +00:00
|
|
|
SkString fName;
|
2012-09-05 18:36:17 +00:00
|
|
|
bool fBulkLoad;
|
|
|
|
QueryType fQuery;
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
static inline SkIRect make_concentric_rects_increasing(SkRandom&, int index, int numRects) {
|
2012-09-05 18:36:17 +00:00
|
|
|
SkIRect out = {0, 0, index + 1, index + 1};
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
static inline SkIRect make_XYordered_rects(SkRandom& rand, int index, int numRects) {
|
2013-08-30 17:27:47 +00:00
|
|
|
SkIRect out;
|
|
|
|
out.fLeft = index % GRID_WIDTH;
|
|
|
|
out.fTop = index / GRID_WIDTH;
|
2013-08-30 18:54:54 +00:00
|
|
|
out.fRight = out.fLeft + 1 + rand.nextU() % (GENERATE_EXTENTS / 3);
|
|
|
|
out.fBottom = out.fTop + 1 + rand.nextU() % (GENERATE_EXTENTS / 3);
|
2013-08-30 17:27:47 +00:00
|
|
|
return out;
|
|
|
|
}
|
2013-09-09 20:09:12 +00:00
|
|
|
static inline SkIRect make_YXordered_rects(SkRandom& rand, int index, int numRects) {
|
2013-08-30 17:27:47 +00:00
|
|
|
SkIRect out;
|
|
|
|
out.fLeft = index / GRID_WIDTH;
|
|
|
|
out.fTop = index % GRID_WIDTH;
|
2013-08-30 18:54:54 +00:00
|
|
|
out.fRight = out.fLeft + 1 + rand.nextU() % (GENERATE_EXTENTS / 3);
|
|
|
|
out.fBottom = out.fTop + 1 + rand.nextU() % (GENERATE_EXTENTS / 3);
|
2013-08-30 17:27:47 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
static inline SkIRect make_random_rects(SkRandom& rand, int index, int numRects) {
|
2012-09-05 18:36:17 +00:00
|
|
|
SkIRect out;
|
|
|
|
out.fLeft = rand.nextS() % GENERATE_EXTENTS;
|
|
|
|
out.fTop = rand.nextS() % GENERATE_EXTENTS;
|
|
|
|
out.fRight = out.fLeft + 1 + rand.nextU() % (GENERATE_EXTENTS / 5);
|
|
|
|
out.fBottom = out.fTop + 1 + rand.nextU() % (GENERATE_EXTENTS / 5);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxBuildBench, ("XYordered", &make_XYordered_rects, false,
|
2012-09-05 18:36:17 +00:00
|
|
|
SkRTree::Create(5, 16)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxBuildBench, ("XYordered", &make_XYordered_rects, true,
|
2012-09-05 18:36:17 +00:00
|
|
|
SkRTree::Create(5, 16)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxBuildBench, ("(unsorted)XYordered", &make_XYordered_rects, true,
|
2013-08-30 17:27:47 +00:00
|
|
|
SkRTree::Create(5, 16, 1, false)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxQueryBench, ("XYordered", &make_XYordered_rects, true,
|
2012-09-05 18:36:17 +00:00
|
|
|
BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxQueryBench, ("(unsorted)XYordered", &make_XYordered_rects, true,
|
2013-08-30 17:27:47 +00:00
|
|
|
BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16, 1, false)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
2013-08-30 17:27:47 +00:00
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxBuildBench, ("YXordered", &make_YXordered_rects, false,
|
2013-08-30 17:27:47 +00:00
|
|
|
SkRTree::Create(5, 16)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxBuildBench, ("YXordered", &make_YXordered_rects, true,
|
2013-08-30 17:27:47 +00:00
|
|
|
SkRTree::Create(5, 16)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxBuildBench, ("(unsorted)YXordered", &make_YXordered_rects, true,
|
2013-08-30 17:27:47 +00:00
|
|
|
SkRTree::Create(5, 16, 1, false)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxQueryBench, ("YXordered", &make_YXordered_rects, true,
|
2012-09-05 18:36:17 +00:00
|
|
|
BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxQueryBench, ("(unsorted)YXordered", &make_YXordered_rects, true,
|
2013-08-30 17:27:47 +00:00
|
|
|
BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16, 1, false)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
2012-09-05 18:36:17 +00:00
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxBuildBench, ("random", &make_random_rects, false,
|
2013-08-30 17:27:47 +00:00
|
|
|
SkRTree::Create(5, 16)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxBuildBench, ("random", &make_random_rects, true,
|
2013-08-30 17:27:47 +00:00
|
|
|
SkRTree::Create(5, 16)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxBuildBench, ("(unsorted)random", &make_random_rects, true,
|
2013-08-30 17:27:47 +00:00
|
|
|
SkRTree::Create(5, 16, 1, false)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxQueryBench, ("random", &make_random_rects, true,
|
2013-08-30 17:27:47 +00:00
|
|
|
BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxQueryBench, ("(unsorted)random", &make_random_rects, true,
|
2013-08-30 17:27:47 +00:00
|
|
|
BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16, 1, false)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
2013-08-30 17:27:47 +00:00
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxBuildBench, ("concentric",
|
2013-08-30 17:27:47 +00:00
|
|
|
&make_concentric_rects_increasing, true, SkRTree::Create(5, 16)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxBuildBench, ("(unsorted)concentric",
|
2013-08-30 17:27:47 +00:00
|
|
|
&make_concentric_rects_increasing, true, SkRTree::Create(5, 16, 1, false)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxQueryBench, ("concentric", &make_concentric_rects_increasing, true,
|
2013-08-30 17:27:47 +00:00
|
|
|
BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|
|
|
|
DEF_BENCH(
|
|
|
|
return SkNEW_ARGS(BBoxQueryBench, ("(unsorted)concentric", &make_concentric_rects_increasing, true,
|
2013-08-30 17:27:47 +00:00
|
|
|
BBoxQueryBench::kRandom_QueryType, SkRTree::Create(5, 16, 1, false)));
|
2013-09-13 19:52:27 +00:00
|
|
|
)
|