美文网首页
统计方法耗时

统计方法耗时

作者: ModestStorm | 来源:发表于2022-11-02 20:29 被阅读0次

方式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