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