idlize

Форк
0
/
test_performance.ts 
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

16
import { nativeModule } from "@koalaui/arkoala"
17
import { ArkCommonPeer } from "@arkoala/arkui/ArkCommonPeer"
18
import { ArkNavigationPeer } from "@arkoala/arkui/ArkNavigationPeer"
19
import { ArkUINodeType } from "@arkoala/arkui/ArkUINodeType"
20
// imports required intarfaces (now generation is disabled)
21
// import { NavigationTitleMode } from "@arkoala/arkui/ArkNavigationInterfaces"
22

23
import {
24
    TEST_COUNT, CALL_COUNT, testString1000, testLength_10_percent,
25
    testLength_number100, testNumber100
26
} from "@arkoala/arkui/test_data"
27
import { withStringResult } from "@koalaui/interop"
28

29
enum DumpOptions {
30
    TOTAL = 0,
31
    AVERAGE,
32
    PEAK,
33
    DETAILS,
34
    CLEAR
35
}
36

37
export function RunPerformanceTest(testName: string, testCnt: number, callCnt: number, testFunc: () => void) {
38
    for (let i = 0; i < testCnt; ++i) {
39
        for (let j = 0; j < callCnt; ++j) {
40
            nativeModule()._StartPerf("perf_counter_self_cost")
41
            // do nothing ===> perf_counter_self_cost about 0.838 us.
42
            nativeModule()._EndPerf("perf_counter_self_cost")
43
            nativeModule()._StartPerf(testName)
44
            testFunc()
45
            nativeModule()._EndPerf(testName)
46
        }
47
    }
48
    console.log(withStringResult(nativeModule()._DumpPerf(DumpOptions.AVERAGE)))
49
    nativeModule()._DumpPerf(DumpOptions.CLEAR)
50
}
51

52
export function startPerformanceTest() {
53
    let peer = new ArkCommonPeer(ArkUINodeType.Common);
54
    RunPerformanceTest("idlize_restoreIdAttribute_testNumber100", TEST_COUNT, CALL_COUNT, () => {
55
        peer.restoreIdAttribute(testNumber100)
56
    });
57
    RunPerformanceTest("idlize_keyAttribute_testString1000", TEST_COUNT, CALL_COUNT, () => {
58
        peer.keyAttribute(testString1000)
59
    });
60
    RunPerformanceTest("idlize_widthAttribute_testLength_10_percent", TEST_COUNT, CALL_COUNT, () => {
61
        peer.widthAttribute(testLength_10_percent)
62
    });
63
    RunPerformanceTest("idlize_widthAttribute_testLength_number100", TEST_COUNT, CALL_COUNT, () => {
64
        peer.widthAttribute(testLength_number100)
65
    });
66
    RunPerformanceTest("idlize_paddingAttribute", TEST_COUNT, CALL_COUNT, () => {
67
        peer.paddingAttribute({
68
            top: testLength_10_percent, right: testLength_10_percent,
69
            bottom: testLength_10_percent, left: testLength_10_percent
70
        })
71
    });
72
    RunPerformanceTest("idlize_backgroundBlurStyleAttribute", TEST_COUNT, CALL_COUNT, () => {
73
        peer.backgroundBlurStyleAttribute(0, {
74
            colorMode: 0,
75
            adaptiveColor: 0,
76
            scale: 1,
77
            blurOptions: {
78
                grayscale: [1, 1]
79
            }
80
        })
81
    });
82

83
    RunPerformanceTest("idlize_linearGradientAttribute", TEST_COUNT, CALL_COUNT, () => {
84
        peer.linearGradientAttribute({
85
            angle: 70,
86
            repeating: false,
87
            direction: 1, //GradientDirection.Top,
88
            colors: [[0xff0000, 0.0], [0x0000ff, 0.3], [0xffff00, 0.5]]
89
        })
90
    });
91
    RunPerformanceTest("idlize_borderAttribute", TEST_COUNT, CALL_COUNT, () => {
92
        peer.borderAttribute({
93
            width: 5,
94
            color: 0,
95
            radius: 25,
96
            style: 1 // BorderStyle.Solid
97
        })
98
    });
99
    let navigation = new ArkNavigationPeer(ArkUINodeType.Common);
100
    RunPerformanceTest("idlize_navigation_titleModeAttribute", TEST_COUNT, CALL_COUNT, () => {
101
        navigation.titleModeAttribute(/*NavigationTitleMode.Free*/0)
102
    });
103
}
104

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.