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.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2012-09-05 18:36:17 +00:00
|
|
|
#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:
|
2014-08-27 17:39:42 +00:00
|
|
|
static const SkScalar GENERATE_EXTENTS = 1000.0f;
|
2012-09-05 18:36:17 +00:00
|
|
|
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
|
|
|
|
2014-08-27 17:39:42 +00:00
|
|
|
typedef SkRect (*MakeRectProc)(SkRandom&, int, int);
|
2012-09-05 18:36:17 +00:00
|
|
|
|
2014-11-18 17:27:49 +00:00
|
|
|
// Time how long it takes to build an R-Tree.
|
2014-06-19 19:32:29 +00:00
|
|
|
class RTreeBuildBench : public Benchmark {
|
2012-09-05 18:36:17 +00:00
|
|
|
public:
|
2014-11-18 17:27:49 +00:00
|
|
|
RTreeBuildBench(const char* name, MakeRectProc proc) : fProc(proc) {
|
2014-10-27 17:27:10 +00:00
|
|
|
fName.printf("rtree_%s_build", name);
|
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-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;
|
2014-10-27 17:27:10 +00:00
|
|
|
SkAutoTMalloc<SkRect> rects(NUM_BUILD_RECTS);
|
|
|
|
for (int i = 0; i < NUM_BUILD_RECTS; ++i) {
|
|
|
|
rects[i] = fProc(rand, i, NUM_BUILD_RECTS);
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2014-11-18 17:27:49 +00:00
|
|
|
SkRTree tree;
|
|
|
|
tree.insert(&rects, NUM_BUILD_RECTS);
|
2014-10-27 17:27:10 +00:00
|
|
|
SkASSERT(rects != NULL); // It'd break this bench if the tree took ownership of rects.
|
2012-09-05 18:36:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
MakeRectProc fProc;
|
2012-09-06 13:38:53 +00:00
|
|
|
SkString fName;
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-09-05 18:36:17 +00:00
|
|
|
};
|
|
|
|
|
2014-11-18 17:27:49 +00:00
|
|
|
// Time how long it takes to perform queries on an R-Tree.
|
2014-06-19 19:32:29 +00:00
|
|
|
class RTreeQueryBench : public Benchmark {
|
2012-09-05 18:36:17 +00:00
|
|
|
public:
|
2014-11-18 17:27:49 +00:00
|
|
|
RTreeQueryBench(const char* name, MakeRectProc proc) : fProc(proc) {
|
2014-10-27 17:27:10 +00:00
|
|
|
fName.printf("rtree_%s_query", name);
|
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-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;
|
2014-10-27 17:27:10 +00:00
|
|
|
SkAutoTMalloc<SkRect> rects(NUM_QUERY_RECTS);
|
|
|
|
for (int i = 0; i < NUM_QUERY_RECTS; ++i) {
|
|
|
|
rects[i] = fProc(rand, i, NUM_QUERY_RECTS);
|
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
|
|
|
}
|
2014-11-18 17:27:49 +00:00
|
|
|
fTree.insert(&rects, NUM_QUERY_RECTS);
|
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
|
|
|
}
|
|
|
|
|
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) {
|
2014-10-02 14:41:56 +00:00
|
|
|
SkTDArray<unsigned> hits;
|
2014-08-27 17:39:42 +00:00
|
|
|
SkRect query;
|
2014-10-27 17:27:10 +00:00
|
|
|
query.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS);
|
|
|
|
query.fTop = rand.nextRangeF(0, GENERATE_EXTENTS);
|
|
|
|
query.fRight = query.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/2);
|
|
|
|
query.fBottom = query.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/2);
|
2014-11-18 17:27:49 +00:00
|
|
|
fTree.search(query, &hits);
|
2012-09-05 18:36:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2014-11-18 17:27:49 +00:00
|
|
|
SkRTree fTree;
|
2012-09-05 18:36:17 +00:00
|
|
|
MakeRectProc fProc;
|
2012-09-06 13:38:53 +00:00
|
|
|
SkString fName;
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-09-05 18:36:17 +00:00
|
|
|
};
|
|
|
|
|
2014-08-27 17:39:42 +00:00
|
|
|
static inline SkRect make_XYordered_rects(SkRandom& rand, int index, int numRects) {
|
|
|
|
SkRect out;
|
|
|
|
out.fLeft = SkIntToScalar(index % GRID_WIDTH);
|
|
|
|
out.fTop = SkIntToScalar(index / GRID_WIDTH);
|
|
|
|
out.fRight = out.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/3);
|
|
|
|
out.fBottom = out.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/3);
|
2013-08-30 17:27:47 +00:00
|
|
|
return out;
|
|
|
|
}
|
2014-08-27 17:39:42 +00:00
|
|
|
static inline SkRect make_YXordered_rects(SkRandom& rand, int index, int numRects) {
|
|
|
|
SkRect out;
|
|
|
|
out.fLeft = SkIntToScalar(index / GRID_WIDTH);
|
|
|
|
out.fTop = SkIntToScalar(index % GRID_WIDTH);
|
|
|
|
out.fRight = out.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/3);
|
|
|
|
out.fBottom = out.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/3);
|
2013-08-30 17:27:47 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2014-08-27 17:39:42 +00:00
|
|
|
static inline SkRect make_random_rects(SkRandom& rand, int index, int numRects) {
|
|
|
|
SkRect out;
|
|
|
|
out.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS);
|
|
|
|
out.fTop = rand.nextRangeF(0, GENERATE_EXTENTS);
|
|
|
|
out.fRight = out.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/5);
|
|
|
|
out.fBottom = out.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/5);
|
2012-09-05 18:36:17 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2014-11-18 17:27:49 +00:00
|
|
|
static inline SkRect make_concentric_rects(SkRandom&, int index, int numRects) {
|
|
|
|
return SkRect::MakeWH(SkIntToScalar(index+1), SkIntToScalar(index+1));
|
|
|
|
}
|
|
|
|
|
2012-09-05 18:36:17 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-11-18 17:27:49 +00:00
|
|
|
DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("XY", &make_XYordered_rects)));
|
|
|
|
DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("YX", &make_YXordered_rects)));
|
|
|
|
DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("random", &make_random_rects)));
|
|
|
|
DEF_BENCH(return SkNEW_ARGS(RTreeBuildBench, ("concentric", &make_concentric_rects)));
|
|
|
|
|
|
|
|
DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("XY", &make_XYordered_rects)));
|
|
|
|
DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("YX", &make_YXordered_rects)));
|
|
|
|
DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("random", &make_random_rects)));
|
|
|
|
DEF_BENCH(return SkNEW_ARGS(RTreeQueryBench, ("concentric", &make_concentric_rects)));
|