Android quick tip: use System.arraycopy()

Well it’s a well known fact that the java native function System.arraycopy() is a useful way to copy one array to another since it is native, but is that also the case for Android? And if so, how much more useful is it? To answer these questions I have made a simple test and ran it as a java program on my PC and than as an Android activity. Here is the test for the PC: Here are the results while running it from my PC (java 7, 8GB memory, CPU intel i5): Naive algorithm – 14 ms System.arraycopy(); – 6 ms. Arraycopy does the task in less than half of the time. Now to use it on Android – here is the code: * Notice I have reduced the size of the Array from 10 million to 1 million, this is due to restrictions on memory for applications in Android. The results from running it on my device (nexus 1): Naive algorithm – 182 ms System.arraycopy(); – 12 ms. This means that the fact that System.arraycopy() is better than the regular copy is even more true for Android. In short than, always use System.arraycopy() especially on Android. Test for Continue reading Android quick tip: use System.arraycopy()