14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_cideclare function print(arg:any) : string;
174514f5e3Sopenharmony_cideclare interface ArkTools {
184514f5e3Sopenharmony_ci    timeInUs(arg:any):number
194514f5e3Sopenharmony_ci}
204514f5e3Sopenharmony_ci
214514f5e3Sopenharmony_cifunction testAdd() {
224514f5e3Sopenharmony_ci    let key = "key";
234514f5e3Sopenharmony_ci    let mySet = new Set();
244514f5e3Sopenharmony_ci    let start = ArkTools.timeInUs();
254514f5e3Sopenharmony_ci    for (let i = 0; i < 1_000_000; i++) {
264514f5e3Sopenharmony_ci        mySet.add(key);
274514f5e3Sopenharmony_ci    }
284514f5e3Sopenharmony_ci    let end = ArkTools.timeInUs();
294514f5e3Sopenharmony_ci    let time = (end - start) / 1000
304514f5e3Sopenharmony_ci    print("Set Add:\t" + String(time) + "\tms");
314514f5e3Sopenharmony_ci}
324514f5e3Sopenharmony_ci
334514f5e3Sopenharmony_cifunction testDelete() {
344514f5e3Sopenharmony_ci    const mySet = new Set();
354514f5e3Sopenharmony_ci    let key = "key";
364514f5e3Sopenharmony_ci    mySet.add(key);
374514f5e3Sopenharmony_ci    let start = ArkTools.timeInUs();
384514f5e3Sopenharmony_ci    for (let i = 0; i < 1_000_000; i++) {
394514f5e3Sopenharmony_ci        mySet.delete(key);
404514f5e3Sopenharmony_ci    }
414514f5e3Sopenharmony_ci    let end = ArkTools.timeInUs();
424514f5e3Sopenharmony_ci    let time = (end - start) / 1000
434514f5e3Sopenharmony_ci    print("Set Delete:\t" + String(time) + "\tms");
444514f5e3Sopenharmony_ci}
454514f5e3Sopenharmony_ci
464514f5e3Sopenharmony_cifunction testHas() {
474514f5e3Sopenharmony_ci    const mySet = new Set();
484514f5e3Sopenharmony_ci    let key = "key";
494514f5e3Sopenharmony_ci    mySet.add(key);
504514f5e3Sopenharmony_ci    let start = ArkTools.timeInUs();
514514f5e3Sopenharmony_ci    for (let i = 0; i < 1_000_000; i++) {
524514f5e3Sopenharmony_ci        mySet.has(key);
534514f5e3Sopenharmony_ci    }
544514f5e3Sopenharmony_ci    let end = ArkTools.timeInUs();
554514f5e3Sopenharmony_ci    let time = (end - start) / 1000
564514f5e3Sopenharmony_ci    print("Set Has:\t" + String(time) + "\tms");
574514f5e3Sopenharmony_ci}
584514f5e3Sopenharmony_ci
594514f5e3Sopenharmony_cifunction setElements(value1, value2, set) {}
604514f5e3Sopenharmony_cifunction testForEach() {
614514f5e3Sopenharmony_ci    const mySet = new Set();
624514f5e3Sopenharmony_ci    let key = "key";
634514f5e3Sopenharmony_ci    mySet.add(key);
644514f5e3Sopenharmony_ci    let start = ArkTools.timeInUs();
654514f5e3Sopenharmony_ci    for (let i = 0; i < 1_000_000; i++) {
664514f5e3Sopenharmony_ci        mySet.forEach(setElements);
674514f5e3Sopenharmony_ci    }
684514f5e3Sopenharmony_ci    let end = ArkTools.timeInUs();
694514f5e3Sopenharmony_ci    let time = (end - start) / 1000
704514f5e3Sopenharmony_ci    print("Set ForEach:\t" + String(time) + "\tms");
714514f5e3Sopenharmony_ci}
724514f5e3Sopenharmony_ci
734514f5e3Sopenharmony_cifunction testClear() {
744514f5e3Sopenharmony_ci    const mySet = new Set();
754514f5e3Sopenharmony_ci    let key = "key";
764514f5e3Sopenharmony_ci    mySet.add(key);
774514f5e3Sopenharmony_ci    let start = ArkTools.timeInUs();
784514f5e3Sopenharmony_ci    for (let i = 0; i < 1_000_000; i++) {
794514f5e3Sopenharmony_ci        mySet.clear();
804514f5e3Sopenharmony_ci    }
814514f5e3Sopenharmony_ci    let end = ArkTools.timeInUs();
824514f5e3Sopenharmony_ci    let time = (end - start) / 1000
834514f5e3Sopenharmony_ci    print("Set Clear:\t" + String(time) + "\tms");
844514f5e3Sopenharmony_ci}
854514f5e3Sopenharmony_ci
864514f5e3Sopenharmony_cifunction testValues() {
874514f5e3Sopenharmony_ci    const mySet = new Set();
884514f5e3Sopenharmony_ci    let start = ArkTools.timeInUs();
894514f5e3Sopenharmony_ci    for (let i = 0; i < 1_000_000; i++) {
904514f5e3Sopenharmony_ci        mySet.values();
914514f5e3Sopenharmony_ci    }
924514f5e3Sopenharmony_ci    let end = ArkTools.timeInUs();
934514f5e3Sopenharmony_ci    let time = (end - start) / 1000
944514f5e3Sopenharmony_ci    print("Set Values:\t" + String(time) + "\tms");
954514f5e3Sopenharmony_ci}
964514f5e3Sopenharmony_ci
974514f5e3Sopenharmony_cifunction testEntries() {
984514f5e3Sopenharmony_ci    const mySet = new Set();
994514f5e3Sopenharmony_ci    let start = ArkTools.timeInUs();
1004514f5e3Sopenharmony_ci    for (let i = 0; i < 1_000_000; i++) {
1014514f5e3Sopenharmony_ci        mySet.entries();
1024514f5e3Sopenharmony_ci    }
1034514f5e3Sopenharmony_ci    let end = ArkTools.timeInUs();
1044514f5e3Sopenharmony_ci    let time = (end - start) / 1000
1054514f5e3Sopenharmony_ci    print("Set Entries:\t" + String(time) + "\tms");
1064514f5e3Sopenharmony_ci}
1074514f5e3Sopenharmony_ci
1084514f5e3Sopenharmony_citestAdd();
1094514f5e3Sopenharmony_citestDelete();
1104514f5e3Sopenharmony_citestHas();
1114514f5e3Sopenharmony_citestForEach();
1124514f5e3Sopenharmony_citestClear();
1134514f5e3Sopenharmony_citestValues();
1144514f5e3Sopenharmony_citestEntries();
115