PathParserBench.cpp revision 4bbc2931263b232fba61807fca00e127573eff42
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
17#include <benchmark/Benchmark.h>
18
19#include "PathParser.h"
20#include "VectorDrawable.h"
21
22#include <SkPath.h>
23
24using namespace android;
25using namespace android::uirenderer;
26
27static const char* sPathString = "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 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";
28
29BENCHMARK_NO_ARG(BM_PathParser_parseStringPathForSkPath);
30void BM_PathParser_parseStringPathForSkPath::Run(int iter) {
31    SkPath skPath;
32    size_t length = strlen(sPathString);
33    PathParser::ParseResult result;
34    StartBenchmarkTiming();
35    for (int i = 0; i < iter; i++) {
36        PathParser::parseStringForSkPath(&skPath, &result, sPathString, length);
37    }
38    StopBenchmarkTiming();
39}
40
41BENCHMARK_NO_ARG(BM_PathParser_parseStringPathForPathData);
42void BM_PathParser_parseStringPathForPathData::Run(int iter) {
43    size_t length = strlen(sPathString);
44    PathData outData;
45    PathParser::ParseResult result;
46    StartBenchmarkTiming();
47    for (int i = 0; i < iter; i++) {
48        PathParser::getPathDataFromString(&outData, &result, sPathString, length);
49    }
50    StopBenchmarkTiming();
51}
52