Are LogCat the most expensive in Android?

I want to run some performance tests of some blocks of code in an Android app. My plan is to measure System.nanoTime()at different points and then spill the difference with Logcat.

However, I was wondering if the calls Log.i()were not really expensive and therefore could distort the results?

Inside, I don’t know what it’s actually doing Log.i(...)- does it write directly to some USB output stream or does it simply put a log message in a queue that needs to be picked up by some kind of asynchronous stream that makes the real one work?

+4
source share
2 answers

, , . ( ). Log. * ,

+4

-, @Blackbelt , - , .

, System.nanoTime(), Traceview, .

, , . :

Log.i("testLogcat", message); // mean execution time: 30465ns 

strings.add("test"); // mean execution time: 962ns 

Object x = new Object(); // mean execution time: 1185ns 

int x = 1+1; // mean execution time: 1053ns

, Log.i() , 30 , , .

, 2 !

  • Log.i() , . , System.nanoTime() , Log.i() WITHIN .
  • Traceview
+1

Source: https://habr.com/ru/post/1606545/


All Articles