1/* 2 * Copyright (c) 2023 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 16declare function print(arg:any) : string; 17declare interface ArkTools { 18 timeInUs(arg:any):number 19} 20 21function testGetVievValue() { 22 var buffer = new ArrayBuffer(8); 23 var dataview = new DataView(buffer); 24 let start = ArkTools.timeInUs(); 25 let res; 26 for (let i = 0; i < 1_000_000; i++) { 27 res = dataview.getInt32(2); 28 } 29 let end = ArkTools.timeInUs(); 30 let time = (end - start) / 1000 31 print(res) 32 print("DataView GetVievValue:\t" + String(time) + "\tms"); 33} 34 35function testSetVievValue() { 36 var buffer = new ArrayBuffer(8); 37 var dataview = new DataView(buffer); 38 let start = ArkTools.timeInUs(); 39 for (let i = 0; i < 1_000_000; i++) { 40 dataview.setInt32(1, 2); 41 } 42 let end = ArkTools.timeInUs(); 43 let time = (end - start) / 1000 44 print("DataView SetVievValue:\t" + String(time) + "\tms"); 45} 46 47function testGetByteLength() { 48 var buffer = new ArrayBuffer(8); 49 var dataview = new DataView(buffer); 50 let start = ArkTools.timeInUs(); 51 let res; 52 for (let i = 0; i < 1_000_000; i++) { 53 res = dataview.byteLength; 54 } 55 let end = ArkTools.timeInUs(); 56 let time = (end - start) / 1000 57 print(res) 58 print("DataView ByteLength:\t" + String(time) + "\tms"); 59} 60 61testSetVievValue(); 62testGetVievValue(); 63testGetByteLength(); 64 65