Mike Reed | 4928229 | 2016-12-14 12:34:06 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 11 | class StreamBench : public Benchmark { |
Mike Reed | 9c457ad | 2016-12-15 14:11:37 -0500 | [diff] [blame] | 12 | SkString fName; |
| 13 | const bool fTestWrite4; |
Mike Reed | 4928229 | 2016-12-14 12:34:06 -0500 | [diff] [blame] | 14 | public: |
Mike Reed | 9c457ad | 2016-12-15 14:11:37 -0500 | [diff] [blame] | 15 | StreamBench(bool testWrite4) : fTestWrite4(testWrite4) { |
| 16 | fName.printf("wstream_%d", testWrite4); |
Mike Reed | 4928229 | 2016-12-14 12:34:06 -0500 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | bool isSuitableFor(Backend backend) override { |
| 20 | return backend == kNonRendering_Backend; |
| 21 | } |
| 22 | |
| 23 | protected: |
| 24 | const char* onGetName() override { return fName.c_str(); } |
| 25 | |
| 26 | void onDraw(int loops, SkCanvas* canvas) override { |
Mike Reed | 9c457ad | 2016-12-15 14:11:37 -0500 | [diff] [blame] | 27 | const char t3[] = { 1, 2, 3 }; |
| 28 | const char t5[] = { 1, 2, 3, 4, 5 }; |
Mike Reed | 4928229 | 2016-12-14 12:34:06 -0500 | [diff] [blame] | 29 | for (int i = 0; i < loops*100; ++i) { |
| 30 | SkDynamicMemoryWStream stream; |
Mike Reed | 9c457ad | 2016-12-15 14:11:37 -0500 | [diff] [blame] | 31 | 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 Reed | 4928229 | 2016-12-14 12:34:06 -0500 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | private: |
| 44 | typedef Benchmark INHERITED; |
| 45 | }; |
| 46 | |
| 47 | /////////////////////////////////////////////////////////////////////////////// |
| 48 | |
Mike Reed | 9c457ad | 2016-12-15 14:11:37 -0500 | [diff] [blame] | 49 | DEF_BENCH(return new StreamBench(false);) |
| 50 | DEF_BENCH(return new StreamBench(true);) |