@ohos.util.Stack
@ohos.util.Stack.locate
测试用例 1: 测试在最坏情况下(查找元素不存在的情况)Stack容器的locate接口,Stack长度为100000
function test_locate(loopCount: number) {
let stack = new Stack<number>();
for (let i = 0; i < 100000; i++) {
stack.push(i);
}
const startTime = new Date();
for (let i = 0; i < loopCount; i++) {
stack.locate(100000);
}
const endTime = new Date();
const executionTime = endTime.getTime() - startTime.getTime();
const averageTime = executionTime / loopCount;
console.log(`!${test_id}: ${averageTime} ms`);
}
function test_locate2(loopCount: number) {
let stack = new Stack<number>();
for (let i = 0; i < 10000000; i++) {
stack.push(i);
}
const startTime = new Date();
for (let i = 0; i < loopCount; i++) {
stack.locate(0);
}
const endTime = new Date();
const executionTime = endTime.getTime() - startTime.getTime();
const averageTime = executionTime / loopCount;
console.log(`!${test_id}: ${averageTime} ms`);
}
测试用例 | 测试平台 | 运行时间 |
---|---|---|
测试用例 1 | Huawei Phone | 0.037333 ms |
测试用例 2 | Huawei Phone | 0.000065 ms |
@ohos.util.Stack.push
测试用例 1: 测试Stack容器push接口
function test_push(loopCount: number) {
let stack = new Stack<number>();
const startTime = new Date();
for (let i = 0; i < loopCount; i++) {
stack.push(1);
}
const endTime = new Date();
const executionTime = endTime.getTime() - startTime.getTime();
const averageTime = executionTime / loopCount;
console.log(`!${test_id}: ${averageTime} ms`);
}
测试用例 | 测试平台 | 运行时间 |
---|---|---|
测试用例 1 | Huawei Phone | 0.000128 ms |
@ohos.util.Stack.peek
测试用例 1: 测试Stack容器peek接口
function test_peek(loopCount: number){
let stack = new Stack<number>();
for (let i = 0; i < 5000000; i++) {
stack.push(i);
}
const startTime = new Date();
for (let i = 0; i < loopCount; i++) {
stack.peek();
}
const endTime = new Date();
const executionTime = endTime.getTime() - startTime.getTime();
const averageTime = executionTime / loopCount;
console.log(`!${test_id}: ${averageTime} ms`);
}
测试用例 | 测试平台 | 运行时间 |
---|---|---|
测试用例 1 | Huawei Phone | 0.000060 ms |
@ohos.util.Stack.pop
测试用例 1: 测试Stack容器pop接口
function test_pop(loopCount: number) {
let stack = new Stack<number>();
for (let i = 0; i < 500000; i++) {
stack.push(i);
}
const startTime = new Date();
for (let i = 0; i < loopCount; i++) {
stack.pop();
}
const endTime = new Date();
const executionTime = endTime.getTime() - startTime.getTime();
const averageTime = executionTime / loopCount;
console.log(`!${test_id}: ${averageTime} ms`);
}
测试用例 | 测试平台 | 运行时间 |
---|---|---|
测试用例 1 | Huawei Phone | 0.000064 ms |