1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "module_info.h" 17 18 #include <benchmark/benchmark.h> 19 20 using namespace std; 21 using namespace OHOS; 22 using namespace OHOS::AppExecFwk; 23 24 namespace { 25 /** 26 * @tc.name: BenchmarkTestForReadFromParcel 27 * @tc.desc: Testcase for testing 'ReadFromParcel' function. 28 * @tc.type: FUNC 29 * @tc.require: Issue Number 30 */ BenchmarkTestForReadFromParcel(benchmark::State & state)31 static void BenchmarkTestForReadFromParcel(benchmark::State &state) 32 { 33 ModuleInfo info; 34 info.moduleName = "entry"; 35 Parcel parcel; 36 info.Marshalling(parcel); 37 for (auto _ : state) { 38 /* @tc.steps: step1.call ReadFromParcel in loop */ 39 info.ReadFromParcel(parcel); 40 } 41 } 42 43 /** 44 * @tc.name: BenchmarkTestForMarshalling 45 * @tc.desc: Testcase for testing 'Marshalling' function. 46 * @tc.type: FUNC 47 * @tc.require: Issue Number 48 */ BenchmarkTestForMarshalling(benchmark::State & state)49 static void BenchmarkTestForMarshalling(benchmark::State &state) 50 { 51 ModuleInfo info; 52 info.moduleName = "entry"; 53 Parcel parcel; 54 for (auto _ : state) { 55 /* @tc.steps: step1.call Marshalling in loop */ 56 info.Marshalling(parcel); 57 } 58 } 59 60 /** 61 * @tc.name: BenchmarkTestForUnmarshalling 62 * @tc.desc: Testcase for testing 'Unmarshalling' function. 63 * @tc.type: FUNC 64 * @tc.require: Issue Number 65 */ BenchmarkTestForUnmarshalling(benchmark::State & state)66 static void BenchmarkTestForUnmarshalling(benchmark::State &state) 67 { 68 ModuleInfo info; 69 info.moduleName = "entry"; 70 Parcel parcel; 71 info.Marshalling(parcel); 72 for (auto _ : state) { 73 /* @tc.steps: step1.call Unmarshalling in loop */ 74 info.Unmarshalling(parcel); 75 } 76 } 77 78 BENCHMARK(BenchmarkTestForReadFromParcel)->Iterations(1000); 79 BENCHMARK(BenchmarkTestForMarshalling)->Iterations(1000); 80 BENCHMARK(BenchmarkTestForUnmarshalling)->Iterations(1000); 81 } 82 83 BENCHMARK_MAIN();