OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "Resources.h" | 9 #include "Resources.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
11 #include "SkImage.h" | 11 #include "SkImage.h" |
12 #include "SkPDFBitmap.h" | 12 #include "SkPDFBitmap.h" |
13 #include "SkPDFUtils.h" | |
13 #include "SkPixmap.h" | 14 #include "SkPixmap.h" |
15 #include "SkRandom.h" | |
14 | 16 |
15 namespace { | 17 namespace { |
16 struct NullWStream : public SkWStream { | 18 struct NullWStream : public SkWStream { |
17 NullWStream() : fN(0) {} | 19 NullWStream() : fN(0) {} |
18 bool write(const void*, size_t n) override { fN += n; return true; } | 20 bool write(const void*, size_t n) override { fN += n; return true; } |
19 size_t bytesWritten() const override { return fN; } | 21 size_t bytesWritten() const override { return fN; } |
20 size_t fN; | 22 size_t fN; |
21 }; | 23 }; |
22 | 24 |
23 static void test_pdf_object_serialization(SkPDFObject* object) { | 25 static void test_pdf_object_serialization(SkPDFObject* object) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 SkAutoTUnref<SkPDFObject> object( | 140 SkAutoTUnref<SkPDFObject> object( |
139 new SkPDFSharedStream(fAsset->duplicate())); | 141 new SkPDFSharedStream(fAsset->duplicate())); |
140 test_pdf_object_serialization(object); | 142 test_pdf_object_serialization(object); |
141 } | 143 } |
142 } | 144 } |
143 | 145 |
144 private: | 146 private: |
145 SkAutoTDelete<SkStreamAsset> fAsset; | 147 SkAutoTDelete<SkStreamAsset> fAsset; |
146 }; | 148 }; |
147 | 149 |
150 // Test speed of SkPDFUtils::FloatToDecimal for typical floats that | |
151 // might be found in a PDF document. | |
152 struct PDFScalarBench : public Benchmark { | |
153 bool isSuitableFor(Backend b) override { | |
154 return b == kNonRendering_Backend; | |
155 } | |
156 const char* onGetName() override { return "PDFScalar"; } | |
157 void onDraw(int loops, SkCanvas*) override { | |
158 SkRandom random(0x5EED); | |
mtklein
2016/02/25 17:00:47
why not the default seed?
| |
159 char dst[SkPDFUtils::kMaximumFloatDecimalLength]; | |
160 while (loops-- > 0) { | |
161 auto f = random.nextRangeF(-500.0f, 1500.0f); | |
162 (void)SkPDFUtils::FloatToDecimal(f, dst); | |
163 } | |
164 } | |
165 }; | |
166 | |
148 } // namespace | 167 } // namespace |
149 DEF_BENCH(return new PDFImageBench;) | 168 DEF_BENCH(return new PDFImageBench;) |
150 DEF_BENCH(return new PDFJpegImageBench;) | 169 DEF_BENCH(return new PDFJpegImageBench;) |
151 DEF_BENCH(return new PDFCompressionBench;) | 170 DEF_BENCH(return new PDFCompressionBench;) |
171 DEF_BENCH(return new PDFScalarBench;) | |
OLD | NEW |