Native code performance
As we already know, native code can run faster with better processing speed. This can be further optimized for a specific CPU architecture. The main reason behind this performance boost is the use of pointers in memory operations. However, it depends on the developer and the coding style.
Let's look at a simple example where we can have a better understanding of performance gain in native language.
Consider this Java code:
int[] testArray = new int[1000]; for ( int i = 0; i < 1000; ++ i) { testArray[i] = i; }
In this case, the address of 1000 fields in the array is handled by JVM (DVM in the case of an Android Dalvik system). So, the interpreter parses to the ith position and performs an assignment operation each time, which takes a lot of time.
Now, let's implement the same functionality using native C/C++ language and use pointers:
int testArray[1000]; int *ptrArray = testArray; for ( int i = 0; i < 1000; ++ i) { *ptrArray = i; ptrArray += i * sizeof...