加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
3_meas_repeat_vs.ets 2.51 KB
一键复制 编辑 原始数据 按行查看 历史
/**
* Compare performance of RepeatVirtualScroll vs LazyForEach
*
* This is slightly modified version of 0_meas.ets for RepeatVirtualScroll
*/
const ITEMS_PER_OP = 50;
//
@ComponentV2
struct MyRepeatVSComp {
@Local arr: number[] = [];
@Local totalCount:number = 0;
base: number = 0;
// for measurements
@Local timeStart: number = 0;
@Local timeEnd: number = 0;
build() {
Column({space:5}) {
Text("REPEAT-VS UPDATE")
Text(`delay:${this.timeEnd - this.timeStart} cnt:${this.arr.length}`)
List() {
Repeat(this.arr)
.virtualScroll({ totalCount: this.totalCount })
.each((row) => {
ListItem() {
Row() {
// something heavy to render
Text("😐")
Text("😐")
Text("😐")
// added background to make area-change visible
Text(`${row.item}`).backgroundColor(0xeeeeee)
.onAreaChange(() => {
this.timeEnd = Date.now();
//aceTrace.end()
})
}
.width('90%').border({width:1})
}
})
.key(row => "Id_" + JSON.stringify(row))
}
.height(500)
Button(`Add ${ITEMS_PER_OP} Uniq Rows`)
.onClick(() => {
this.timeStart = this.timeEnd = Date.now()
for (let i = 0; i < ITEMS_PER_OP; i++) {
this.arr.unshift( this.base + i );
}
this.base += ITEMS_PER_OP
this.totalCount = this.arr.length
//aceTrace.begin('MyRepeatVSComp ACE_TRACE BEGIN')
})
Button(`Update First ${ITEMS_PER_OP} Rows`)
.onClick(() => {
this.timeStart = this.timeEnd = Date.now()
for (let i = 0; i < Math.min(ITEMS_PER_OP, this.arr.length); i++) {
this.arr[i] = -this.arr[i]
}
//aceTrace.begin('MyRepeatVSComp ACE_TRACE BEGIN')
})
Button(`Delete First ${ITEMS_PER_OP} Rows`)
.onClick(() => {
this.timeStart = this.timeEnd = Date.now()
this.arr.splice(0, ITEMS_PER_OP);
this.totalCount = this.arr.length
//aceTrace.begin('MyRepeatVSComp ACE_TRACE BEGIN')
})
}
}
}
@Entry
@ComponentV2
struct ParentComp {
build() {
Column() {
Row() {
Text('3_meas.ets').fontSize(32)
}
Row() {
Column() {
MyRepeatVSComp()
}.width('50%')
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化