scroggo@google.com | dd39488 | 2012-07-24 20:47:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 The Android Open Source Project |
| 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "bench/Benchmark.h" |
| 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "src/core/SkWriter32.h" |
scroggo@google.com | dd39488 | 2012-07-24 20:47:55 +0000 | [diff] [blame] | 11 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 12 | class WriterBench : public Benchmark { |
scroggo@google.com | dd39488 | 2012-07-24 20:47:55 +0000 | [diff] [blame] | 13 | public: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 14 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 15 | return backend == kNonRendering_Backend; |
| 16 | } |
scroggo@google.com | dd39488 | 2012-07-24 20:47:55 +0000 | [diff] [blame] | 17 | |
| 18 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 19 | const char* onGetName() override { |
scroggo@google.com | dd39488 | 2012-07-24 20:47:55 +0000 | [diff] [blame] | 20 | return "writer"; |
| 21 | } |
| 22 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 23 | void onDraw(int loops, SkCanvas*) override { |
scroggo@google.com | dd39488 | 2012-07-24 20:47:55 +0000 | [diff] [blame] | 24 | static const char gStr[] = "abcdefghimjklmnopqrstuvwxyz"; |
| 25 | static const size_t gLen = strlen(gStr); |
commit-bot@chromium.org | 1938242 | 2014-01-14 20:51:26 +0000 | [diff] [blame] | 26 | SkWriter32 writer; |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 27 | for (int i = 0; i < loops; i++) { |
scroggo@google.com | dd39488 | 2012-07-24 20:47:55 +0000 | [diff] [blame] | 28 | for (size_t j = 0; j <= gLen; j++) { |
| 29 | writer.writeString(gStr, j); |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 35 | typedef Benchmark INHERITED; |
scroggo@google.com | dd39488 | 2012-07-24 20:47:55 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | //////////////////////////////////////////////////////////////////////////////// |
| 39 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 40 | DEF_BENCH( return new WriterBench(); ) |