We are trying to encode GIF using Animated-gif-Encoder-For-Android. We found that the time taken to encode for same GIF on Lollipop devices is much less than time taken on Marshmallow devices. Major part of encoding GIF is pure arithmetic to quantise colours.
To investigate further we tested with a sample loop of int arithmetic functions.
We found that on
Moto G4 Plus(Android 6.0.1) - it took : 70 ms
Moto E2(Android 5.1) - it took : 25 ms
Can anyone explain this behaviour ? Moto G4 is definitely a more powerful processor than Moto E2. Is it something to do with the Android compiler that changed between Android 5.1 & Android 6.0.1 ???
Specs:
http://www.gsmarena.com/motorola_moto_g4_plus-8050.php
http://www.gsmarena.com/motorola_moto_e_(2nd_gen)-6986.php
Sample Code that was profiled:
private void profilingFuntion(){
int N = 1000; // input array size
int k = 1000; // number of mathematical operations performed on each element
// generate random data
int[] ints = new int[N];
int[] doubles = new int[N];
Random r = new Random(1l);
for (int i = 0; i < N; i++) {
ints[i] = r.nextInt();
doubles[i] = r.nextInt();
}
// measure integer subtractions
long before = System.currentTimeMillis();
for (int i = 1; i < N; i++) {
for (int j = 0; j < k; j++) {
ints[i] -= ints[i-1]; // referring to another element might prevent from optimization also
}
}
if(DEBUG)
Log.d(TAG,"time taken for sub:"+(System.currentTimeMillis()-before));
// measure integer subtractions
before = System.currentTimeMillis();
for (int i = 1; i < N; i++) {
for (int j = 0; j < k; j++) {
doubles[i] += doubles[i-1];
}
}
if(DEBUG)
Log.d(TAG,"time taken for add:"+(System.currentTimeMillis()-before));
}