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 "utils/LinearAllocator.h"
20 
21 #include <vector>
22 
23 using namespace android;
24 using namespace android::uirenderer;
25 
BM_LinearStdAllocator_vectorBaseline(benchmark::State & state)26 static void BM_LinearStdAllocator_vectorBaseline(benchmark::State& state) {
27     while (state.KeepRunning()) {
28         std::vector<char> v;
29         for (int j = 0; j < 200; j++) {
30             v.push_back(j);
31         }
32         benchmark::DoNotOptimize(&v);
33     }
34 }
35 BENCHMARK(BM_LinearStdAllocator_vectorBaseline);
36 
BM_LinearStdAllocator_vector(benchmark::State & state)37 static void BM_LinearStdAllocator_vector(benchmark::State& state) {
38     while (state.KeepRunning()) {
39         LinearAllocator la;
40         LinearStdAllocator<void*> stdAllocator(la);
41         std::vector<char, LinearStdAllocator<char> > v(stdAllocator);
42         for (int j = 0; j < 200; j++) {
43             v.push_back(j);
44         }
45         benchmark::DoNotOptimize(&v);
46     }
47 }
48 BENCHMARK(BM_LinearStdAllocator_vector);
49