This is an interesting question, and I like the analysis of @misiu_mp, so I decided to update it with the 2016 test on Nexus 7 running Android 6.0.1. Here is the test code:
public void runSpeedTest() { long startTime; long[] times = new long[100000]; long[] staticTimes = new long[100000]; for (int i = 0; i < times.length; i++) { startTime = System.nanoTime(); for (int j = 0; j < 1000; j++) { emptyMethod(); } times[i] = (System.nanoTime() - startTime) / 1000; startTime = System.nanoTime(); for (int j = 0; j < 1000; j++) { emptyStaticMethod(); } staticTimes[i] = (System.nanoTime() - startTime) / 1000; } int timesSum = 0; for (int i = 0; i < times.length; i++) { timesSum += times[i]; Log.d("status", "time," + times[i]); sleep(); } int timesStaticSum = 0; for (int i = 0; i < times.length; i++) { timesStaticSum += staticTimes[i]; Log.d("status", "statictime," + staticTimes[i]); sleep(); } sleep(); Log.d("status", "final speed = " + (timesSum / times.length)); Log.d("status", "final static speed = " + (timesStaticSum / times.length)); } private void sleep() { try { Thread.sleep(10); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private void emptyMethod() { } private static void emptyStaticMethod() { }
Added sleep() to prevent Log.d buffer Log.d .
I played with him many times, and the results were pretty compatible with @misiu_mp:
10^5 iterations of 1000 calls to an empty static void function: 29ns/call 10^5 iterations of 1000 calls to an empty non-static void function: 34ns/call
A static method call has always been a little faster than a non-static method call, but it would seem that a) the gap has narrowed significantly since Android 2.3.2 and b) the cost of calls to an empty method is still static or not.
Looking at the histogram once reveals something interesting. Most calls, whether static or not, take between 30-40 ns and carefully look at the data, they are almost all 30ns for sure.

Running the same code with empty cycles (commenting on method calls) leads to an average speed of 8 ns, however, about 3/4 of the measured times is 0ns, while the remainder is exactly 30 ns.
I am not sure how to account for this data, but I am not sure that the conclusions of @misiu_mp are still saved. The difference between empty static and non-stationary methods is insignificant, and the predominance of measurements is exactly 30 ns. At the same time, it seems that there is still an unnecessary cost of empty methods.
Mark cramer
source share