From aadb44e77ba84996e71694aaf28c833394a7839b Mon Sep 17 00:00:00 2001 From: liangguirong Date: Fri, 22 Dec 2023 11:28:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E6=97=B6=E9=95=BF=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liangguirong --- entry/src/ohosTest/ets/test/List.test.ets | 2 + .../test/TestInterfaceResponseTime.test.ets | 155 ++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 entry/src/ohosTest/ets/test/TestInterfaceResponseTime.test.ets diff --git a/entry/src/ohosTest/ets/test/List.test.ets b/entry/src/ohosTest/ets/test/List.test.ets index cab4910..2e607c2 100644 --- a/entry/src/ohosTest/ets/test/List.test.ets +++ b/entry/src/ohosTest/ets/test/List.test.ets @@ -15,9 +15,11 @@ import abilityTest from './Ability.test' import ChineseHelperTest from './ChineseHelper.test' import PinyinHelperTest from './PinyinHelper.test' +import PinyinHelperJsunit from './TestInterfaceResponseTime.test' export default function testsuite() { PinyinHelperTest() ChineseHelperTest() abilityTest() + PinyinHelperJsunit() } \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/TestInterfaceResponseTime.test.ets b/entry/src/ohosTest/ets/test/TestInterfaceResponseTime.test.ets new file mode 100644 index 0000000..d78018c --- /dev/null +++ b/entry/src/ohosTest/ets/test/TestInterfaceResponseTime.test.ets @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, it, expect, TestType } from '@ohos/hypium' +import { ChineseHelper, pinyin4js, PinyinFormat, PinyinHelper } from '@ohos/pinyin4js'; + + +export default function PinyinHelperJsunit() { + + describe('PinyinHelper', ()=> { + const BASE_COUNT=2000 + const HTTP_COUNT=2 + const BASELINE_HASSIMECASR=500 + const BASELINE_CREATEHTTP=500 + const BASELINE_REQUEST=2500 + const BASELINE_DESTROY=30 + + // pinyin4js.convertToPinyinString + it('TestPinyinHelperInterface_001', TestType.PERFORMANCE, async (done:Function)=> { + let startTime = new Date().getTime(); + for (let index = 0; index < BASE_COUNT; index++) { + pinyin4js.convertToPinyinString('厦门你好大厦厦门', ',', pinyin4js.WITH_TONE_MARK) + } + let endTime = new Date().getTime(); + console.info("TestPinyinHelperInterface_001 endTime" + endTime) + let averageTime = ((endTime - startTime)*1000 / BASE_COUNT) + console.log("TestPinyinHelperInterface_001 averageTime:"+averageTime+"μs"); + expect(averageTime { + let startTime = new Date().getTime(); + for (let index = 0; index < BASE_COUNT; index++) { + PinyinHelper.getShortPinyin('厦门你好大厦厦门') + } + let endTime = new Date().getTime(); + console.info("TestPinyinHelperInterface_002 endTime" + endTime) + let averageTime = ((endTime - startTime)*1000 / BASE_COUNT) + console.log("TestPinyinHelperInterface_002 averageTime:"+averageTime+"μs"); + expect(averageTime>BASELINE_CREATEHTTP).assertTrue(); + done() + }) + + // PinyinHelper.hasMultiPinyin + it('TestPinyinHelperInterface_003', TestType.PERFORMANCE, async (done:Function)=> { + let startTime = new Date().getTime(); + for (let index = 0; index < BASE_COUNT; index++) { + PinyinHelper.hasMultiPinyin('厦') + } + let endTime = new Date().getTime(); + console.info("TestPinyinHelperInterface_003 endTime" + endTime) + let averageTime = ((endTime - startTime)*1000 / BASE_COUNT) + console.log("TestPinyinHelperInterface_003 averageTime:"+averageTime+"μs"); + expect(averageTime { + let startTime = new Date().getTime(); + for (let index = 0; index < BASE_COUNT; index++) { + pinyin4js.convertToPinyinString('厦门你好大厦厦门', ',', PinyinFormat.WITH_TONE_MARK) + } + let endTime = new Date().getTime(); + console.info("TestPinyinHelperInterface_004 endTime" + endTime) + let averageTime = ((endTime - startTime)*1000 / BASE_COUNT) + console.log("TestPinyinHelperInterface_004 averageTime:"+averageTime+"μs"); + expect(averageTime { + let startTime = new Date().getTime(); + for (let index = 0; index < BASE_COUNT; index++) { + ChineseHelper.convertToSimplifiedChinese('臺喪麗') + } + let endTime = new Date().getTime(); + console.info("TestPinyinHelperInterface_005 endTime" + endTime) + let averageTime = ((endTime - startTime)*1000 / BASE_COUNT) + console.log("TestPinyinHelperInterface_005 averageTime:"+averageTime+"μs"); + expect(averageTime { + let startTime = new Date().getTime(); + for (let index = 0; index < BASE_COUNT; index++) { + ChineseHelper.convertToTraditionalChinese('台丧丽') + } + let endTime = new Date().getTime(); + console.info("TestPinyinHelperInterface_006 endTime" + endTime) + let averageTime = ((endTime - startTime)*1000 / BASE_COUNT) + console.log("TestPinyinHelperInterface_006 averageTime:"+averageTime+"μs"); + expect(averageTime>BASELINE_CREATEHTTP).assertTrue(); + done() + }) + + //ChineseHelper.containsChinese + it('TestPinyinHelperInterface_007', TestType.PERFORMANCE, async (done:Function)=> { + let startTime = new Date().getTime(); + for (let index = 0; index < BASE_COUNT; index++) { + ChineseHelper.containsChinese('12台丧丽') + } + let endTime = new Date().getTime(); + console.info("TestPinyinHelperInterface_007 endTime" + endTime) + let averageTime = ((endTime - startTime)*1000 / BASE_COUNT) + console.log("TestPinyinHelperInterface_007 averageTime:"+averageTime+"μs"); + expect(averageTime { + let startTime = new Date().getTime(); + for (let index = 0; index < BASE_COUNT; index++) { + ChineseHelper.isTraditionalChinese('臺') + } + let endTime = new Date().getTime(); + console.info("TestPinyinHelperInterface_008 endTime" + endTime) + let averageTime = ((endTime - startTime)*1000 / BASE_COUNT) + console.log("TestPinyinHelperInterface_008 averageTime:"+averageTime+"μs"); + expect(averageTime { + let startTime = new Date().getTime(); + for (let index = 0; index < BASE_COUNT; index++) { + ChineseHelper.isChinese('台') + } + let endTime = new Date().getTime(); + console.info("TestPinyinHelperInterface_009 endTime" + endTime) + let averageTime = ((endTime - startTime)*1000 / BASE_COUNT) + console.log("TestPinyinHelperInterface_009 averageTime:"+averageTime+"μs"); + expect(averageTime