Best method to measure execution time in Android?

前端 未结 5 1761
臣服心动
臣服心动 2020-12-24 02:03

What is best method to measure execution time of Android code snippet?

I have a section of code before and after which I want to place timestamps to find out it\'s e

5条回答
  •  情歌与酒
    2020-12-24 02:22

    What would be the best way to measure execution time

    System.nanoTime() is probably a good choice. Jake Wharton is using that with Hugo, for example.

    and get good precision

    This is not strictly possible, as anything can happen on the device while your method is executing. Those external factors will affect your time measurements, by stealing away CPU time, tying up I/O channels, etc. You need to average your tests across several runs to try to average out those external factors, and accuracy/precision will suffer as a result.

    And, as Marcin Orlowski notes, to actually figure out why you are consuming certain amounts of time, use Traceview.

提交回复
热议问题