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:
parent
7a1cc6766d
commit
49282296b6
41
bench/StreamBench.cpp
Normal file
41
bench/StreamBench.cpp
Normal 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;)
|
@ -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",
|
||||
|
@ -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()));
|
||||
|
Loading…
Reference in New Issue
Block a user