O'Reilly logo

Pro Android Apps Performance Optimization by Hervé Guihot

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Measuring Time

How much time an operation or sequence of operations takes to complete is a critical piece of information when it is time to optimize code. Without knowing how much time is spent doing something, your optimizations are impossible to measure. Java and Android provide the following simple APIs your application can use to measure time and therefore performance:

  • System.currentTimeMillis
  • System.nanoTime
  • Debug.threadCpuTimeNanos
  • SystemClock.currentThreadTimeMillis
  • SystemClock.elapsedRealtime
  • SystemClock.uptimeMillis

Typically, your application needs to make two calls to these methods as a single call is hardly meaningful. To measure time, your application needs a start time and an end time, and performance is measured as the difference ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required