Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions | Variables
GrMemoryPoolBench.cpp File Reference
#include "bench/Benchmark.h"
#include "src/base/SkRandom.h"
#include "src/gpu/ganesh/GrMemoryPool.h"
#include <type_traits>

Go to the source code of this file.

Classes

class  GrMemoryPoolBench
 

Functions

template<typename T >
static void run_stack (GrMemoryPool *pool, int loops)
 
template<typename T >
static void run_queue (GrMemoryPool *pool, int loops)
 
template<typename T >
static void run_pushpop (GrMemoryPool *pool, int loops)
 
template<typename T >
static void run_random (GrMemoryPool *pool, int loops)
 

Variables

static const int kLargePool = 10 * (1 << 10)
 
static const int kSmallPool = GrMemoryPool::kMinAllocationSize
 

Function Documentation

◆ run_pushpop()

template<typename T >
static void run_pushpop ( GrMemoryPool pool,
int  loops 
)
static

Definition at line 91 of file GrMemoryPoolBench.cpp.

91 {
92 static const int kMaxObjects = 4 * (1 << 10);
93 T* objs[kMaxObjects];
94 for (int i = 0; i < loops; ++i) {
95 // Push N objects into the pool (or heap if pool is null)
96 for (int j = 0; j < kMaxObjects; ++j) {
97 if (pool) {
98 objs[j] = (T*) pool->allocate(sizeof(T));
99 pool->release(objs[j]);
100 } else {
101 objs[j] = new T;
102 delete objs[j];
103 }
104 }
105
106 // Everything has been cleaned up for the next loop
107 }
108}
AutoreleasePool pool
#define T

◆ run_queue()

template<typename T >
static void run_queue ( GrMemoryPool pool,
int  loops 
)
static

Definition at line 67 of file GrMemoryPoolBench.cpp.

67 {
68 static const int kMaxObjects = 4 * (1 << 10);
69 T* objs[kMaxObjects];
70 for (int i = 0; i < loops; ++i) {
71 // Push N objects into the pool (or heap if pool is null)
72 for (int j = 0; j < kMaxObjects; ++j) {
73 objs[j] = pool ? (T*) pool->allocate(sizeof(T)) : new T;
74 }
75 // Pop N objects off in FIFO order
76 for (int j = 0; j < kMaxObjects; ++j) {
77 if (pool) {
78 pool->release(objs[j]);
79 } else {
80 delete objs[j];
81 }
82 }
83
84 // Everything has been cleaned up for the next loop
85 }
86}

◆ run_random()

template<typename T >
static void run_random ( GrMemoryPool pool,
int  loops 
)
static

Definition at line 112 of file GrMemoryPoolBench.cpp.

112 {
113 static const int kMaxObjects = 4 * (1 << 10);
114 T* objs[kMaxObjects];
115 for (int i = 0; i < kMaxObjects; ++i) {
116 objs[i] = nullptr;
117 }
118
119 auto del = [&](int j) {
120 // Delete
121 if (pool) {
122 pool->release(objs[j]);
123 } else {
124 delete objs[j];
125 }
126 objs[j] = nullptr;
127 };
128
129 SkRandom r;
130 for (int i = 0; i < loops; ++i) {
131 // Execute 2*kMaxObjects operations, which should average to N create and N destroy,
132 // followed by a small number of remaining deletions.
133 for (int j = 0; j < 2 * kMaxObjects; ++j) {
134 int k = r.nextRangeU(0, kMaxObjects-1);
135 if (objs[k]) {
136 del(k);
137 } else {
138 // Create
139 objs[k] = pool ? (T*) pool->allocate(sizeof(T)) : new T;
140 }
141 }
142
143 // Ensure everything is null for the next loop
144 for (int j = 0; j < kMaxObjects; ++j) {
145 if (objs[j]) {
146 del(j);
147 }
148 }
149 }
150}
uint32_t nextRangeU(uint32_t min, uint32_t max)
Definition SkRandom.h:80

◆ run_stack()

template<typename T >
static void run_stack ( GrMemoryPool pool,
int  loops 
)
static

Definition at line 43 of file GrMemoryPoolBench.cpp.

43 {
44 static const int kMaxObjects = 4 * (1 << 10);
45 T* objs[kMaxObjects];
46 for (int i = 0; i < loops; ++i) {
47 // Push N objects into the pool (or heap if pool is null)
48 for (int j = 0; j < kMaxObjects; ++j) {
49 objs[j] = pool ? (T*) pool->allocate(sizeof(T)) : new T;
50 }
51 // Pop N objects off in LIFO order
52 for (int j = kMaxObjects - 1; j >= 0; --j) {
53 if (pool) {
54 pool->release(objs[j]);
55 } else {
56 delete objs[j];
57 }
58 }
59
60 // Everything has been cleaned up for the next loop
61 }
62}

Variable Documentation

◆ kLargePool

const int kLargePool = 10 * (1 << 10)
static

Definition at line 189 of file GrMemoryPoolBench.cpp.

◆ kSmallPool

const int kSmallPool = GrMemoryPool::kMinAllocationSize
static

Definition at line 190 of file GrMemoryPoolBench.cpp.