2015-10-19 19:15:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrTTopoSort.h"
|
2015-10-19 19:15:55 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
2015-10-19 19:15:55 +00:00
|
|
|
|
|
|
|
class TopoSortBench : public Benchmark {
|
|
|
|
public:
|
|
|
|
TopoSortBench() { }
|
|
|
|
|
|
|
|
~TopoSortBench() override {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return kNonRendering_Backend == backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override {
|
|
|
|
return "sort_topo_rand";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delayed initialization only done if onDraw will be called.
|
|
|
|
void onDelayedSetup() override {
|
2019-03-20 16:12:10 +00:00
|
|
|
ToolUtils::TopoTestNode::AllocNodes(&fGraph, kNumElements);
|
2015-10-19 19:15:55 +00:00
|
|
|
|
|
|
|
for (int i = kNumElements-1; i > 0; --i) {
|
|
|
|
int numEdges = fRand.nextU() % (kMaxEdges+1);
|
|
|
|
|
|
|
|
for (int j = 0; j < numEdges; ++j) {
|
|
|
|
int dep = fRand.nextU() % i;
|
|
|
|
|
2018-02-07 22:08:21 +00:00
|
|
|
fGraph[i]->dependsOn(fGraph[dep].get());
|
2015-10-19 19:15:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
for (int j = 0; j < fGraph.count(); ++j) {
|
|
|
|
fGraph[j]->reset();
|
|
|
|
}
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
ToolUtils::TopoTestNode::Shuffle(&fGraph, &fRand);
|
2015-10-19 19:15:55 +00:00
|
|
|
|
2020-11-16 19:58:56 +00:00
|
|
|
SkDEBUGCODE(bool actualResult =) GrTTopoSort<ToolUtils::TopoTestNode>(&fGraph);
|
2015-10-19 19:15:55 +00:00
|
|
|
SkASSERT(actualResult);
|
|
|
|
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
for (int j = 0; j < fGraph.count(); ++j) {
|
|
|
|
SkASSERT(fGraph[j]->check());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const int kNumElements = 1000;
|
|
|
|
static const int kMaxEdges = 5;
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
SkTArray<sk_sp<ToolUtils::TopoTestNode>> fGraph;
|
2015-10-19 19:15:55 +00:00
|
|
|
SkRandom fRand;
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2015-10-19 19:15:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_BENCH( return new TopoSortBench(); )
|