idlize
103 строки · 3.9 Кб
1/*
2* Copyright (c) 2024 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
16import { nativeModule } from "@koalaui/arkoala"17import { ArkCommonPeer } from "@arkoala/arkui/ArkCommonPeer"18import { ArkNavigationPeer } from "@arkoala/arkui/ArkNavigationPeer"19import { ArkUINodeType } from "@arkoala/arkui/ArkUINodeType"20// imports required intarfaces (now generation is disabled)
21// import { NavigationTitleMode } from "@arkoala/arkui/ArkNavigationInterfaces"
22
23import {24TEST_COUNT, CALL_COUNT, testString1000, testLength_10_percent,25testLength_number100, testNumber10026} from "@arkoala/arkui/test_data"27import { withStringResult } from "@koalaui/interop"28
29enum DumpOptions {30TOTAL = 0,31AVERAGE,32PEAK,33DETAILS,34CLEAR35}
36
37export function RunPerformanceTest(testName: string, testCnt: number, callCnt: number, testFunc: () => void) {38for (let i = 0; i < testCnt; ++i) {39for (let j = 0; j < callCnt; ++j) {40nativeModule()._StartPerf("perf_counter_self_cost")41// do nothing ===> perf_counter_self_cost about 0.838 us.42nativeModule()._EndPerf("perf_counter_self_cost")43nativeModule()._StartPerf(testName)44testFunc()45nativeModule()._EndPerf(testName)46}47}48console.log(withStringResult(nativeModule()._DumpPerf(DumpOptions.AVERAGE)))49nativeModule()._DumpPerf(DumpOptions.CLEAR)50}
51
52export function startPerformanceTest() {53let peer = new ArkCommonPeer(ArkUINodeType.Common);54RunPerformanceTest("idlize_restoreIdAttribute_testNumber100", TEST_COUNT, CALL_COUNT, () => {55peer.restoreIdAttribute(testNumber100)56});57RunPerformanceTest("idlize_keyAttribute_testString1000", TEST_COUNT, CALL_COUNT, () => {58peer.keyAttribute(testString1000)59});60RunPerformanceTest("idlize_widthAttribute_testLength_10_percent", TEST_COUNT, CALL_COUNT, () => {61peer.widthAttribute(testLength_10_percent)62});63RunPerformanceTest("idlize_widthAttribute_testLength_number100", TEST_COUNT, CALL_COUNT, () => {64peer.widthAttribute(testLength_number100)65});66RunPerformanceTest("idlize_paddingAttribute", TEST_COUNT, CALL_COUNT, () => {67peer.paddingAttribute({68top: testLength_10_percent, right: testLength_10_percent,69bottom: testLength_10_percent, left: testLength_10_percent70})71});72RunPerformanceTest("idlize_backgroundBlurStyleAttribute", TEST_COUNT, CALL_COUNT, () => {73peer.backgroundBlurStyleAttribute(0, {74colorMode: 0,75adaptiveColor: 0,76scale: 1,77blurOptions: {78grayscale: [1, 1]79}80})81});82
83RunPerformanceTest("idlize_linearGradientAttribute", TEST_COUNT, CALL_COUNT, () => {84peer.linearGradientAttribute({85angle: 70,86repeating: false,87direction: 1, //GradientDirection.Top,88colors: [[0xff0000, 0.0], [0x0000ff, 0.3], [0xffff00, 0.5]]89})90});91RunPerformanceTest("idlize_borderAttribute", TEST_COUNT, CALL_COUNT, () => {92peer.borderAttribute({93width: 5,94color: 0,95radius: 25,96style: 1 // BorderStyle.Solid97})98});99let navigation = new ArkNavigationPeer(ArkUINodeType.Common);100RunPerformanceTest("idlize_navigation_titleModeAttribute", TEST_COUNT, CALL_COUNT, () => {101navigation.titleModeAttribute(/*NavigationTitleMode.Free*/0)102});103}
104