I have a serious problem with my final project. I was asked to develop a mobile application using PhoneGap to support multiple platforms. Then I was told to compare the features of PhoneGap vs Native , so I decided to test it on Android.
I wrote an example function and measured the time it took to achieve in JavaScript for PhoneGap and in Java for Native Android . And the funny thing is that the JavaScript function takes 10 times less time to complete, and all this time I thought that the Native functions are much faster.
Here is my JavaScript code for PhoneGap:
var array = new Array();
var start = new Date().getTime();
for (var i = 0; i < 1000000; i++) {
var j = i + Math.random();
if (j % 2 == 0)
j = 1;
else
j = 0;
array.push(j);
}
var end = new Date().getTime();
var time = end-start;
var div = document.getElementById('result');
div.innerHTML = "Result time= " + time;
And my Java code for Native:
long startTime = System.currentTimeMillis();
ArrayList<Integer> array = new ArrayList<Integer>();
for (int i = 0; i < 1000000; i++) {
Random r = new Random();
int j = i + r.nextInt();
if (j % 2 == 0)
j = 1;
else
j = 0;
array.add(j);
}
long endTime = System.currentTimeMillis();
long time = endTime - startTime;
t1.setTextColor(Color.BLACK);
t1.setText("Result time= "
+ Long.toString(time));
Output for the first: 350 ms on average
Output for the second: 3600 ms on average
I am testing
Samsung Galaxy Note 10.1 Tablet
Is it correct? Or did I miss something and made a serious mistake?
Thank you very much for your help.
-------------- -------------- Update
after posting
Random r = new Random ()
outside the cycle, the new time required to complete the cycle is 750 ms . But with the help of Phonegap, the speed is twice as fast, can I conclude that for numerical treatment Telephony is better than Native on Android?