Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: bench/StackBench.cpp

Issue 127223004: For comparison, add std::vector. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: undeprecate Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/common_conditions.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/StackBench.cpp
diff --git a/bench/StackBench.cpp b/bench/StackBench.cpp
index 61af99fb1a22c964bd84c1e609bfbeb80e2f4b3d..43888bdc376595c62f808040a42bbf8bd88673ce 100644
--- a/bench/StackBench.cpp
+++ b/bench/StackBench.cpp
@@ -12,6 +12,7 @@
#include "SkDeque.h"
#include "SkTArray.h"
#include "SkTDArray.h"
+#include <vector>
// This file has several benchmarks using various data structures to do stack-like things:
// - push
@@ -78,6 +79,16 @@ BENCH(TDArray_Serial) {
}
}
+BENCH(vector_Serial) {
+ std::vector<int> s;
+ for (int i = 0; i < K; i++) s.push_back(i);
+
+ volatile int junk = 0;
+ for (int j = 0; j < loops; j++) {
+ for (size_t i = 0; i < s.size(); i++) junk += s[i];
+ }
+}
+
// Add K items, then randomly access them many times.
BENCH(TArray_RandomAccess) {
@@ -102,6 +113,17 @@ BENCH(TDArray_RandomAccess) {
}
}
+BENCH(vector_RandomAccess) {
+ std::vector<int> s;
+ for (int i = 0; i < K; i++) s.push_back(i);
+
+ SkRandom rand;
+ volatile int junk = 0;
+ for (int i = 0; i < K*loops; i++) {
+ junk += s[rand.nextULessThan(K)];
+ }
+}
+
// Push many times.
BENCH(ChunkAlloc_Push) {
@@ -124,6 +146,11 @@ BENCH(TDArray_Push) {
for (int i = 0; i < K*loops; i++) s.push(i);
}
+BENCH(vector_Push) {
+ std::vector<int> s;
+ for (int i = 0; i < K*loops; i++) s.push_back(i);
+}
+
// Push then immediately pop many times.
BENCH(ChunkAlloc_PushPop) {
@@ -158,6 +185,14 @@ BENCH(TDArray_PushPop) {
}
}
+BENCH(vector_PushPop) {
+ std::vector<int> s;
+ for (int i = 0; i < K*loops; i++) {
+ s.push_back(i);
+ s.pop_back();
+ }
+}
+
// Push many items, then pop them all.
BENCH(Deque_PushAllPopAll) {
@@ -177,3 +212,9 @@ BENCH(TDArray_PushAllPopAll) {
for (int i = 0; i < K*loops; i++) s.push(i);
for (int i = 0; i < K*loops; i++) s.pop();
}
+
+BENCH(vector_PushAllPopAll) {
+ std::vector<int> s;
+ for (int i = 0; i < K*loops; i++) s.push_back(i);
+ for (int i = 0; i < K*loops; i++) s.pop_back();
+}
« no previous file with comments | « no previous file | gyp/common_conditions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698