2014-02-27 20:23:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 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"
|
2014-02-27 20:23:22 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrOrderedSet.h"
|
|
|
|
|
|
|
|
static const int NUM_ELEMENTS = 1000;
|
|
|
|
|
|
|
|
// Time how long it takes to build a set
|
2014-06-19 19:32:29 +00:00
|
|
|
class GrOrderedSetBuildBench : public Benchmark {
|
2014-02-27 20:23:22 +00:00
|
|
|
public:
|
|
|
|
GrOrderedSetBuildBench() {
|
|
|
|
fName.append("ordered_set_build");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2014-02-27 20:23:22 +00:00
|
|
|
return kNonRendering_Backend == backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GrOrderedSetBuildBench() {}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2014-02-27 20:23:22 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onPreDraw() override {
|
2014-02-27 20:23:22 +00:00
|
|
|
SkRandom rand;
|
|
|
|
for (int j = 0; j < NUM_ELEMENTS; ++j) {
|
|
|
|
fData[j] = rand.nextU() % NUM_ELEMENTS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) override {
|
2014-02-27 20:23:22 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
GrOrderedSet<int> set;
|
|
|
|
for (int j = 0; j < NUM_ELEMENTS; ++j) {
|
|
|
|
set.insert(fData[j]);
|
|
|
|
}
|
|
|
|
set.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fName;
|
|
|
|
int fData[NUM_ELEMENTS];
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2014-02-27 20:23:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Time how long it takes to find elements in a set
|
2014-06-19 19:32:29 +00:00
|
|
|
class GrOrderedSetFindBench : public Benchmark {
|
2014-02-27 20:23:22 +00:00
|
|
|
public:
|
|
|
|
GrOrderedSetFindBench() {
|
|
|
|
fName.append("ordered_set_find");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2014-02-27 20:23:22 +00:00
|
|
|
return kNonRendering_Backend == backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GrOrderedSetFindBench() {}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2014-02-27 20:23:22 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onPreDraw() override {
|
2014-02-27 20:23:22 +00:00
|
|
|
SkRandom rand;
|
|
|
|
for (int j = 0; j < NUM_ELEMENTS; ++j) {
|
|
|
|
fData[j] = rand.nextU() % 1500;
|
|
|
|
fSet.insert(rand.nextU() % NUM_ELEMENTS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) override {
|
2014-02-27 20:23:22 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
for (int j = 0; j < NUM_ELEMENTS; ++j) {
|
|
|
|
fSet.find(fData[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fName;
|
|
|
|
int fData[NUM_ELEMENTS];
|
|
|
|
GrOrderedSet<int> fSet;
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2014-02-27 20:23:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Time how long it takes to iterate over and remove all elements from set
|
2014-06-19 19:32:29 +00:00
|
|
|
class GrOrderedSetRemoveBench : public Benchmark {
|
2014-02-27 20:23:22 +00:00
|
|
|
public:
|
|
|
|
GrOrderedSetRemoveBench() {
|
|
|
|
fName.append("ordered_set_remove");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2014-02-27 20:23:22 +00:00
|
|
|
return kNonRendering_Backend == backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GrOrderedSetRemoveBench() {}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2014-02-27 20:23:22 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onPreDraw() override {
|
2014-02-27 20:23:22 +00:00
|
|
|
SkRandom rand;
|
|
|
|
for (int j = 0; j < NUM_ELEMENTS; ++j) {
|
|
|
|
fSet.insert(rand.nextU() % NUM_ELEMENTS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) override {
|
2014-02-27 20:23:22 +00:00
|
|
|
typedef GrOrderedSet<int>::Iter SetIter;
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
GrOrderedSet<int> testSet;
|
|
|
|
for (SetIter s = fSet.begin(); fSet.end() != s; ++s) {
|
|
|
|
testSet.insert(*s);
|
|
|
|
}
|
|
|
|
for (int j = 0; j < NUM_ELEMENTS; ++j) {
|
|
|
|
testSet.remove(testSet.find(j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fName;
|
|
|
|
GrOrderedSet<int> fSet;
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2014-02-27 20:23:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_BENCH(return SkNEW_ARGS(GrOrderedSetBuildBench, ());)
|
|
|
|
DEF_BENCH(return SkNEW_ARGS(GrOrderedSetFindBench, ());)
|
|
|
|
DEF_BENCH(return SkNEW_ARGS(GrOrderedSetRemoveBench, ());)
|
|
|
|
#endif
|