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 "bundle_user_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 BundleUserInfo info; 34 Parcel parcel; 35 info.Marshalling(parcel); 36 for (auto _ : state) { 37 /* @tc.steps: step1.call ReadFromParcel in loop */ 38 info.ReadFromParcel(parcel); 39 } 40 } 41 42 /** 43 * @tc.name: BenchmarkTestForMarshalling 44 * @tc.desc: Testcase for testing 'Marshalling' function. 45 * @tc.type: FUNC 46 * @tc.require: Issue Number 47 */ BenchmarkTestForMarshalling(benchmark::State & state)48 static void BenchmarkTestForMarshalling(benchmark::State &state) 49 { 50 BundleUserInfo info; 51 Parcel parcel; 52 for (auto _ : state) { 53 /* @tc.steps: step1.call Marshalling in loop */ 54 info.Marshalling(parcel); 55 } 56 } 57 58 /** 59 * @tc.name: BenchmarkTestForUnmarshalling 60 * @tc.desc: Testcase for testing 'Unmarshalling' function. 61 * @tc.type: FUNC 62 * @tc.require: Issue Number 63 */ BenchmarkTestForUnmarshalling(benchmark::State & state)64 static void BenchmarkTestForUnmarshalling(benchmark::State &state) 65 { 66 BundleUserInfo info; 67 Parcel parcel; 68 info.Marshalling(parcel); 69 for (auto _ : state) { 70 /* @tc.steps: step1.call Unmarshalling in loop */ 71 info.Unmarshalling(parcel); 72 } 73 } 74 75 BENCHMARK(BenchmarkTestForReadFromParcel)->Iterations(1000); 76 BENCHMARK(BenchmarkTestForMarshalling)->Iterations(1000); 77 BENCHMARK(BenchmarkTestForUnmarshalling)->Iterations(1000); 78 } 79 80 BENCHMARK_MAIN();