summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian_Chu <walkingice@0xlab.org>2011-07-28 02:41:44 +0800
committerJulian_Chu <walkingice@0xlab.org>2011-07-28 02:56:29 +0800
commita7c0d4927b3d4ab47fd2833bcf14c2a79dec2404 (patch)
tree7bfe3c5f9a7d6891dfba1b7b80927877d7afbfb2
parentbbe349d0a73286222eb6b4071ade5bc7ecde9bd4 (diff)
download0xbench-a7c0d4927b3d4ab47fd2833bcf14c2a79dec2404.tar.gz
Add Case and Tester of Javascript
It execute SunSpider 0.9.1 to benchmark performance of JavaScript. SunSpider itself repeat several times, all we have to do is just execute and report string result.
-rw-r--r--AndroidManifest.xml9
-rw-r--r--res/layout/javascript.xml12
-rw-r--r--src/org/zeroxlab/benchmark/Benchmark.java3
-rw-r--r--src/org/zeroxlab/benchmark/CaseJavascript.java107
-rw-r--r--src/org/zeroxlab/benchmark/TesterJavascript.java87
5 files changed, 218 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a5f7972..20f9001 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -77,6 +77,15 @@
</activity>
<activity
+ android:name="org.zeroxlab.benchmark.TesterJavascript"
+ android:screenOrientation="nosensor"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
+ <activity
android:name="org.zeroxlab.benchmark.TesterScimark2"
android:screenOrientation="nosensor"
>
diff --git a/res/layout/javascript.xml b/res/layout/javascript.xml
new file mode 100644
index 0000000..47085db
--- /dev/null
+++ b/res/layout/javascript.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+ <WebView android:id="@+id/web"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ />
+</LinearLayout>
+
diff --git a/src/org/zeroxlab/benchmark/Benchmark.java b/src/org/zeroxlab/benchmark/Benchmark.java
index 2eba4de..64ca8e8 100644
--- a/src/org/zeroxlab/benchmark/Benchmark.java
+++ b/src/org/zeroxlab/benchmark/Benchmark.java
@@ -152,6 +152,7 @@ public class Benchmark extends TabActivity implements View.OnClickListener {
setContentView(R.layout.main);
mCases = new LinkedList<Case>();
Case arith = new CaseArithmetic();
+ Case javascript = new CaseJavascript();
Case scimark2 = new CaseScimark2();
Case canvas = new CaseCanvas();
Case glcube = new CaseGLCube();
@@ -178,8 +179,10 @@ public class Benchmark extends TabActivity implements View.OnClickListener {
// mflops
mCases.add(arith);
mCases.add(scimark2);
+ mCases.add(javascript);
mCategory.get(MISC).add(arith);
mCategory.get(MISC).add(scimark2);
+ mCategory.get(MISC).add(javascript);
// 2d
mCases.add(canvas);
diff --git a/src/org/zeroxlab/benchmark/CaseJavascript.java b/src/org/zeroxlab/benchmark/CaseJavascript.java
new file mode 100644
index 0000000..16beb76
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/CaseJavascript.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2011 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Authored by Julian Chu <walkingice@0xlab.org>
+ */
+
+package org.zeroxlab.benchmark;
+
+import java.util.ArrayList;
+
+import android.util.Log;
+
+import android.os.SystemClock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+
+public class CaseJavascript extends Case {
+
+ public static String SUNSPIDER_RESULT = "SUNSPIDER_RESULT";
+ public static String SUNSPIDER_TOTAL = "SUNSPIDER_TOTAL";
+
+ public static int sRepeat = 1;
+ public static int sRound = 1;
+
+ private double mTotal = 0.0;
+
+ protected String[] mJSResults;
+ CaseJavascript() {
+ super("CaseJavascript", "org.zeroxlab.benchmark.TesterJavascript", sRepeat, sRound);
+ mType = "msec";
+ mTags = new String[]{new String("javascript")};
+ }
+
+ public String getTitle() {
+ return "SunSpider";
+ }
+
+ public String getDescription() {
+ return "This benchmark tests the core JavaScript language only, not the DOM or other browser APIs. It is designed to compare different versions of the same browser, and different browsers to each other.";
+ }
+
+ @Override
+ public void clear() {
+ super.clear();
+ mJSResults = new String[sRepeat];
+ }
+
+ @Override
+ public void reset() {
+ super.reset();
+ mJSResults = new String[sRepeat];
+ }
+
+ @Override
+ public String getResultOutput() {
+ String result = "\n";
+ for (int i = 0; i < mJSResults.length; i++) {
+ result += mJSResults[i];
+ result += "\n";
+ }
+ return result;
+ }
+
+ @Override
+ public ArrayList<Scenario> getScenarios () {
+ ArrayList<Scenario> scenarios = new ArrayList<Scenario>();
+
+ Scenario s = new Scenario(getTitle(), mType, mTags);
+ s.mLog = getResultOutput();
+ s.mResults.add(mTotal);
+
+ scenarios.add(s);
+
+ return scenarios;
+ }
+
+ @Override
+ protected boolean saveResult(Intent intent, int index) {
+ String result = intent.getStringExtra(SUNSPIDER_RESULT);
+ mTotal = intent.getDoubleExtra(SUNSPIDER_TOTAL, 0.0);
+
+ if (result == null) {
+ Log.e(TAG, "Weird! cannot find SunSpiderInfo");
+ return false;
+ } else {
+ mJSResults[index] = result;
+ }
+
+ return true;
+ }
+}
diff --git a/src/org/zeroxlab/benchmark/TesterJavascript.java b/src/org/zeroxlab/benchmark/TesterJavascript.java
new file mode 100644
index 0000000..0b0ebf9
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/TesterJavascript.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2011 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Authored by Julian Chu <walkingice@0xlab.org>
+ */
+
+package org.zeroxlab.benchmark;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.Message;
+import android.content.Intent;
+import android.webkit.WebView;
+import android.webkit.WebSettings;
+
+public class TesterJavascript extends Tester {
+
+ protected WebView mWebView;
+ protected WebSettings mSettings;
+
+ private double mTotalTime = 0.0;
+ private String mResult = "";
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.javascript);
+ mWebView = (WebView) findViewById(R.id.web);
+
+ mSettings = mWebView.getSettings();
+ mSettings.setJavaScriptEnabled(true);
+ mWebView.addJavascriptInterface(new MsgCallback(), "ANDROID_OBJ");
+
+ startTester();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ }
+
+ @Override
+ protected String getTag() {
+ return "JavaScript";
+ }
+
+ @Override
+ protected int sleepBeforeStart() {
+ return 1000;
+ }
+
+ @Override
+ protected int sleepBetweenRound() {
+ return 1000;
+ }
+
+ @Override
+ protected void oneRound() {
+ mWebView.loadUrl("file:///android_asset/driver.html");
+ }
+
+ @Override
+ protected boolean saveResult(Intent intent) {
+ intent.putExtra(CaseJavascript.SUNSPIDER_RESULT, mResult);
+ intent.putExtra(CaseJavascript.SUNSPIDER_TOTAL, mTotalTime);
+ return true;
+ }
+
+ class MsgCallback {
+ public void finish(String result) {
+ mResult = result;
+ decreaseCounter();
+ }
+ }
+}