WriterBench.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #include "bench/Benchmark.h"
  8. #include "include/core/SkCanvas.h"
  9. #include "src/core/SkWriter32.h"
  10. class WriterBench : public Benchmark {
  11. public:
  12. bool isSuitableFor(Backend backend) override {
  13. return backend == kNonRendering_Backend;
  14. }
  15. protected:
  16. const char* onGetName() override {
  17. return "writer";
  18. }
  19. void onDraw(int loops, SkCanvas*) override {
  20. static const char gStr[] = "abcdefghimjklmnopqrstuvwxyz";
  21. static const size_t gLen = strlen(gStr);
  22. SkWriter32 writer;
  23. for (int i = 0; i < loops; i++) {
  24. for (size_t j = 0; j <= gLen; j++) {
  25. writer.writeString(gStr, j);
  26. }
  27. }
  28. }
  29. private:
  30. typedef Benchmark INHERITED;
  31. };
  32. ////////////////////////////////////////////////////////////////////////////////
  33. DEF_BENCH( return new WriterBench(); )