aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-08 21:16:04 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-08 21:16:04 +0000
commit506ecc24bfbc5edc3e43830a9fbd815c3d6da96a (patch)
treef1339245d0a7a3bd6bbd4d428861d82c12e3e1ad /bench
parent4b5fba5a3cc29058088a9a62df1da83e1a3c7db0 (diff)
For comparison, add std::vector.
Where I've tested, it's second-place to SkTDArray, though the closest API equivalent in our code is SkTArray, which it's significantly faster than. This is probably a good approximation to how fast we can possibly make something like SkTArray that constructs and destroys its values. In fact, it might be worth trying making SkTArray a thin shim over std::vector. BUG= R=bsalomon@google.com, caryclark@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/127223004 git-svn-id: http://skia.googlecode.com/svn/trunk@12969 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench')
-rw-r--r--bench/StackBench.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/bench/StackBench.cpp b/bench/StackBench.cpp
index 61af99fb1a..43888bdc37 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();
+}