PhoneGap performance measurement results

I was wondering how much is loss in performance is one would write application in PhoneGap and javascript instead of native code. I wrote 2 very basic programs one in android and second in PhoneGap. This program did standard busy looping and common string operation indexOf in the for loop. One interesting issue i found is that when you use body onload and do not finish in time then you will get error “Application Error: The connection to the server was unsuccessful. (file:///android_asset/www/index.html)”

3 different loop times were measured in javascript and native android java. Examlpe Code in Android  was :

package com.marguspala.perftest;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class PerfTestAndroidActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        String text="1234567890";
        long start = System.currentTimeMillis();
        for(int i = 1; i<100000;i++){
            text.indexOf("0");
        }
        long end= System.currentTimeMillis();
        TextView tv = (TextView)findViewById(R.id.textView1);
        tv.setText("It took: "+(end-start)+"ms.");
    }
}

Phoneap and javascript was:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js">

</script>
<script type="text/javascript">
    function calculate() {
        var text = "1234567890";
        var start = new Date().getTime();
        for ( var i = 0; i < 10000000; i++) {
            text.indexOf("0");
        }
        var end = new Date().getTime();
        var div = document.getElementById("text");
        div.innerHTML = "It took: " + (end - start) + "ms";
    }
</script>
</head>
<body>
    <div id="text">Hello phonegap</div>
    <a href="#" onclick="calculate()">calculate</a>
</body>
</html>

It turns out that javascript is roughly 3 times slower than android 2.3.5

100 000 cycles:
Android: 0,1s
PhoneGap: 0,3s

1 000 000 cycles:
Android: 0,8s
PhoneGap: 3s

10 000 000 cycles:
Android: 7,5s
PhoneGap: 26s


Leave a Reply

Your email address will not be published.


*