blob: e89b207ac57d3ad4c62ac64dd9c3a29b6c995372 [file] [log] [blame]
Mike Reed49282292016-12-14 12:34:06 -05001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "Benchmark.h"
9#include "SkStream.h"
10
11class StreamBench : public Benchmark {
Mike Reed9c457ad2016-12-15 14:11:37 -050012 SkString fName;
13 const bool fTestWrite4;
Mike Reed49282292016-12-14 12:34:06 -050014public:
Mike Reed9c457ad2016-12-15 14:11:37 -050015 StreamBench(bool testWrite4) : fTestWrite4(testWrite4) {
16 fName.printf("wstream_%d", testWrite4);
Mike Reed49282292016-12-14 12:34:06 -050017 }
18
19 bool isSuitableFor(Backend backend) override {
20 return backend == kNonRendering_Backend;
21 }
22
23protected:
24 const char* onGetName() override { return fName.c_str(); }
25
26 void onDraw(int loops, SkCanvas* canvas) override {
Mike Reed9c457ad2016-12-15 14:11:37 -050027 const char t3[] = { 1, 2, 3 };
28 const char t5[] = { 1, 2, 3, 4, 5 };
Mike Reed49282292016-12-14 12:34:06 -050029 for (int i = 0; i < loops*100; ++i) {
30 SkDynamicMemoryWStream stream;
Mike Reed9c457ad2016-12-15 14:11:37 -050031 for (int j = 0; j < 10000; ++j) {
32 if (fTestWrite4) {
33 stream.write32(j);
34 stream.write32(j+j);
35 } else {
36 stream.write(t3, 3);
37 stream.write(t5, 5);
38 }
Mike Reed49282292016-12-14 12:34:06 -050039 }
40 }
41 }
42
43private:
44 typedef Benchmark INHERITED;
45};
46
47///////////////////////////////////////////////////////////////////////////////
48
Mike Reed9c457ad2016-12-15 14:11:37 -050049DEF_BENCH(return new StreamBench(false);)
50DEF_BENCH(return new StreamBench(true);)