统计方法耗时
方式1
fun testCostTime(){
var list = listOf<Int>(1000)
Thread.sleep(1000)
}
// 耗时打印
val timeCost = measureTimeMillis {
testCostTime()
}
println("the code run time is 耗时:$timeCost")
方式2
//不使用Sequences序列,使用普通的集合操作
fun computeRunTime(action: (() -> Unit)?) {
val startTime = System.currentTimeMillis()
action?.invoke()
println("the code run time is ${System.currentTimeMillis() - startTime}")
}
// 方式2
computeRunTime {
testCostTime()
}
本文标题:统计方法耗时
本文链接:https://www.haomeiwen.com/subject/fhxstdtx.html
网友评论