Doris Liu | f59cb78 | 2015-11-10 10:36:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
John Reck | 0418afa3 | 2016-03-07 13:24:25 -0800 | [diff] [blame] | 17 | #include <benchmark/benchmark.h> |
Doris Liu | f59cb78 | 2015-11-10 10:36:17 -0800 | [diff] [blame] | 18 | |
| 19 | #include "PathParser.h" |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 20 | #include "VectorDrawable.h" |
Doris Liu | f59cb78 | 2015-11-10 10:36:17 -0800 | [diff] [blame] | 21 | |
| 22 | #include <SkPath.h> |
| 23 | |
| 24 | using namespace android; |
| 25 | using namespace android::uirenderer; |
| 26 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 27 | static const char* sPathString = |
| 28 | "M 1 1 m 2 2, l 3 3 L 3 3 H 4 h4 V5 v5, Q6 6 6 6 q 6 6 6 6t 7 7 T 7 7 C 8 8 8 8 8 8 c 8 8 " |
| 29 | "8 8 8 8 S 9 9 9 9 s 9 9 9 9 A 10 10 0 1 1 10 10 a 10 10 0 1 1 10 10"; |
Doris Liu | 804618d | 2015-11-16 22:48:34 -0800 | [diff] [blame] | 30 | |
John Reck | 0418afa3 | 2016-03-07 13:24:25 -0800 | [diff] [blame] | 31 | void BM_PathParser_parseStringPathForSkPath(benchmark::State& state) { |
Doris Liu | f59cb78 | 2015-11-10 10:36:17 -0800 | [diff] [blame] | 32 | SkPath skPath; |
Doris Liu | 804618d | 2015-11-16 22:48:34 -0800 | [diff] [blame] | 33 | size_t length = strlen(sPathString); |
Doris Liu | 1e67f08 | 2015-11-12 15:57:45 -0800 | [diff] [blame] | 34 | PathParser::ParseResult result; |
John Reck | 0418afa3 | 2016-03-07 13:24:25 -0800 | [diff] [blame] | 35 | while (state.KeepRunning()) { |
Doris Liu | b35da39 | 2016-04-12 11:06:23 -0700 | [diff] [blame] | 36 | PathParser::parseAsciiStringForSkPath(&skPath, &result, sPathString, length); |
John Reck | 0418afa3 | 2016-03-07 13:24:25 -0800 | [diff] [blame] | 37 | benchmark::DoNotOptimize(&result); |
| 38 | benchmark::DoNotOptimize(&skPath); |
Doris Liu | 804618d | 2015-11-16 22:48:34 -0800 | [diff] [blame] | 39 | } |
Doris Liu | 804618d | 2015-11-16 22:48:34 -0800 | [diff] [blame] | 40 | } |
John Reck | 0418afa3 | 2016-03-07 13:24:25 -0800 | [diff] [blame] | 41 | BENCHMARK(BM_PathParser_parseStringPathForSkPath); |
Doris Liu | 804618d | 2015-11-16 22:48:34 -0800 | [diff] [blame] | 42 | |
John Reck | 0418afa3 | 2016-03-07 13:24:25 -0800 | [diff] [blame] | 43 | void BM_PathParser_parseStringPathForPathData(benchmark::State& state) { |
Doris Liu | 804618d | 2015-11-16 22:48:34 -0800 | [diff] [blame] | 44 | size_t length = strlen(sPathString); |
| 45 | PathData outData; |
| 46 | PathParser::ParseResult result; |
John Reck | 0418afa3 | 2016-03-07 13:24:25 -0800 | [diff] [blame] | 47 | while (state.KeepRunning()) { |
Doris Liu | b35da39 | 2016-04-12 11:06:23 -0700 | [diff] [blame] | 48 | PathParser::getPathDataFromAsciiString(&outData, &result, sPathString, length); |
John Reck | 0418afa3 | 2016-03-07 13:24:25 -0800 | [diff] [blame] | 49 | benchmark::DoNotOptimize(&result); |
| 50 | benchmark::DoNotOptimize(&outData); |
Doris Liu | f59cb78 | 2015-11-10 10:36:17 -0800 | [diff] [blame] | 51 | } |
Doris Liu | f59cb78 | 2015-11-10 10:36:17 -0800 | [diff] [blame] | 52 | } |
John Reck | 0418afa3 | 2016-03-07 13:24:25 -0800 | [diff] [blame] | 53 | BENCHMARK(BM_PathParser_parseStringPathForPathData); |