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