add tests/bench for dynamicwstream

BUG=skia:

Change-Id: I5a995b63b1a2975cce8101717777eaa6fc12af21
Reviewed-on: https://skia-review.googlesource.com/6035
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2016-12-14 12:34:06 -05:00 committed by Skia Commit-Bot
parent 7a1cc6766d
commit 49282296b6
3 changed files with 45 additions and 0 deletions

41
bench/StreamBench.cpp Normal file
View File

@ -0,0 +1,41 @@
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Benchmark.h"
#include "SkStream.h"
class StreamBench : public Benchmark {
SkString fName;
public:
StreamBench() {
fName.printf("wstream");
}
bool isSuitableFor(Backend backend) override {
return backend == kNonRendering_Backend;
}
protected:
const char* onGetName() override { return fName.c_str(); }
void onDraw(int loops, SkCanvas* canvas) override {
for (int i = 0; i < loops*100; ++i) {
SkDynamicMemoryWStream stream;
for (int j = 0; j < 100000; ++j) {
stream.write32(j);
stream.write32(j+j);
}
}
}
private:
typedef Benchmark INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
DEF_BENCH(return new StreamBench;)

View File

@ -111,6 +111,7 @@ bench_sources = [
"$_bench/SKPAnimationBench.cpp",
"$_bench/SKPBench.cpp",
"$_bench/SkRasterPipelineBench.cpp",
"$_bench/StreamBench.cpp",
"$_bench/SortBench.cpp",
"$_bench/StrokeBench.cpp",
"$_bench/SwizzleBench.cpp",

View File

@ -352,6 +352,7 @@ DEF_TEST(StreamPeek_BlockMemoryStream, rep) {
SkRandom rand(kSeed << 1);
uint8_t buffer[4096];
SkDynamicMemoryWStream dynamicMemoryWStream;
size_t totalWritten = 0;
for (int i = 0; i < 32; ++i) {
// Randomize the length of the blocks.
size_t size = rand.nextRangeU(1, sizeof(buffer));
@ -359,6 +360,8 @@ DEF_TEST(StreamPeek_BlockMemoryStream, rep) {
buffer[j] = valueSource.nextU() & 0xFF;
}
dynamicMemoryWStream.write(buffer, size);
totalWritten += size;
REPORTER_ASSERT(rep, totalWritten == dynamicMemoryWStream.bytesWritten());
}
std::unique_ptr<SkStreamAsset> asset(dynamicMemoryWStream.detachAsStream());
sk_sp<SkData> expected(SkData::MakeUninitialized(asset->getLength()));