Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
TopoSortBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "bench/Benchmark.h"
10#include "src/base/SkRandom.h"
12
13#include "tools/ToolUtils.h"
14
15using namespace skia_private;
16
17class TopoSortBench : public Benchmark {
18public:
20
21 ~TopoSortBench() override {
22 }
23
24 bool isSuitableFor(Backend backend) override {
26 }
27
28protected:
29 const char* onGetName() override {
30 return "sort_topo_rand";
31 }
32
33 // Delayed initialization only done if onDraw will be called.
34 void onDelayedSetup() override {
35 ToolUtils::TopoTestNode::AllocNodes(&fGraph, kNumElements);
36
37 for (int i = kNumElements-1; i > 0; --i) {
38 int numEdges = fRand.nextU() % (kMaxEdges+1);
39
40 for (int j = 0; j < numEdges; ++j) {
41 int dep = fRand.nextU() % i;
42
43 fGraph[i]->dependsOn(fGraph[dep].get());
44 }
45 }
46 }
47
48 void onDraw(int loops, SkCanvas*) override {
49 for (int i = 0; i < loops; ++i) {
50 for (int j = 0; j < fGraph.size(); ++j) {
51 fGraph[j]->reset();
52 }
53
55
56 SkDEBUGCODE(bool actualResult =) GrTTopoSort<ToolUtils::TopoTestNode>(fGraph);
57 SkASSERT(actualResult);
58
59#ifdef SK_DEBUG
60 for (int j = 0; j < fGraph.size(); ++j) {
61 SkASSERT(fGraph[j]->check());
62 }
63#endif
64 }
65 }
66
67private:
68 static const int kNumElements = 1000;
69 static const int kMaxEdges = 5;
70
72 SkRandom fRand;
73
74 using INHERITED = Benchmark;
75};
76
77///////////////////////////////////////////////////////////////////////////////
78
79DEF_BENCH( return new TopoSortBench(); )
#define DEF_BENCH(code)
Definition Benchmark.h:20
const char * backend
#define check(reporter, ref, unref, make, kill)
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
uint32_t nextU()
Definition SkRandom.h:42
static void AllocNodes(skia_private::TArray< sk_sp< ToolUtils::TopoTestNode > > *graph, int num)
Definition ToolUtils.h:229
static void Shuffle(SkSpan< sk_sp< TopoTestNode > > graph, SkRandom *rand)
Definition ToolUtils.h:247
~TopoSortBench() override
bool isSuitableFor(Backend backend) override
void onDraw(int loops, SkCanvas *) override
const char * onGetName() override
void onDelayedSetup() override
void reset(int n)
Definition SkTArray.h:139
int size() const
Definition SkTArray.h:416