Kotlin runCatching try-catch耗时比较

avatar
作者
筋斗云
阅读量:0

Kotlin runCatching try-catch耗时比较

 

 

fun main(args: Array<String>) {     val lists = arrayListOf("z")      val idx = 10      /**      *纳秒统计      *      * ns(nanosecond):纳秒。一秒的10亿分之一,10的-9次方秒。      *   1纳秒=0.000001 毫秒      *   1纳秒=0.000000001秒      */      val t1 = System.nanoTime()     kotlin.runCatching {         lists[idx]     }.onFailure {         //println("error1")     }      val t2 = System.nanoTime()      try {         lists[idx]     } catch (e: Exception) {         //println("error2")     }     val t3 = System.nanoTime()      println("${t2 - t1}ns ${t3 - t2}ns ${(t2 - t1) / (t3 - t2)}") }

 

 

8493500ns 129600ns 65

 

 

 

Kotlin异常处理runCatching,getOrDefault,getOrNull run(2)_kotlin.runcatchin getorthrow 返回值小于等于0-CSDN博客文章浏览阅读215次。b-catch: java.lang.RuntimeException: b发生异常。kotlin异常处理try-catch-finally。kotlin异常处理try-catch-finally_zhangphil的博客-CSDN博客。b-catch: java.lang.RuntimeException: b发生异常。kotlin异常处理try-catch-finally。kotlin异常处理try-catch-finally_zhangphil的博客-CSDN博客。_kotlin.runcatchin getorthrow 返回值小于等于0https://blog.csdn.net/zhangphil/article/details/133279933runCatching异常捕获onSuccess/onFailure返回函数,Kotlin_runcatching 函数finally-CSDN博客文章浏览阅读717次,点赞8次,收藏8次。文章浏览阅读93次。kotlin异常处理try-catch-finally。kotlin异常处理try-catch-finally_zhangphil的博客-CSDN博客。kotlin异常处理try-catch-finally。kotlin异常处理try-catch-finally_zhangphil的博客-CSDN博客。文章浏览阅读533次。kotlin异常处理try-catch-finally。kotlin异常处理try-catch-finally_zhangphil的博客-CSDN博客。_runcatching 函数finallyhttps://blog.csdn.net/zhangphil/article/details/135048822

Kotlin异常处理runCatching,getOrNull,onFailure,onSuccess(1)_kotlin runcatching性能问题-CSDN博客文章浏览阅读761次。b-catch: java.lang.RuntimeException: b发生异常。kotlin异常处理try-catch-finally。kotlin异常处理try-catch-finally_zhangphil的博客-CSDN博客。_kotlin runcatching性能问题https://blog.csdn.net/zhangphil/article/details/133279853

 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!