2 * Copyright (C) 2011 0xlab - http://0xlab.org/
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * Authored by Julian Chu <walkingice@0xlab.org>
19 package org.zeroxlab.benchmark;
21 import java.util.ArrayList;
23 import android.util.Log;
25 import android.os.SystemClock;
27 import android.app.Activity;
28 import android.content.Context;
29 import android.content.BroadcastReceiver;
30 import android.content.Intent;
31 import android.os.Bundle;
33 import java.lang.Float;
35 public class CaseJavascript extends Case {
37 public static String SUNSPIDER_RESULT = "SUNSPIDER_RESULT";
38 public static String SUNSPIDER_FORMATTED_RESULT = "SUNSPIDER_FORMATTED_RESULT";
39 public static String SUNSPIDER_TOTAL = "SUNSPIDER_TOTAL";
41 public static int sRepeat = 1;
42 public static int sRound = 1;
44 private double mTotal = 0.0;
46 protected String[] mJSResults;
47 protected String mFormattedResult;
49 super("CaseJavascript", "org.zeroxlab.benchmark.TesterJavascript", sRepeat, sRound);
51 mTags = new String[]{new String("javascript")};
54 public String getTitle() {
58 public String getDescription() {
59 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.";
65 mJSResults = new String[sRepeat];
71 mJSResults = new String[sRepeat];
75 public String getResultOutput() {
77 for (int i = 0; i < mJSResults.length; i++) {
78 result += mJSResults[i];
85 public ArrayList<Scenario> getScenarios () {
87 ArrayList<Scenario> scenarios = new ArrayList<Scenario>();
88 String results[] = mFormattedResult.split("\n");
89 for (String result: results) {
90 String name_time[] = result.split("\t");
91 String title = getTitle() + ":" + name_time[0];
92 Log.i(TAG, "JS title: " + title);
93 Log.i(TAG, "JS time: " + name_time[1]);
95 Scenario s = new Scenario(title, mType, mTags);
96 s.mResults.add( Double.parseDouble(name_time[1]) );
104 protected boolean saveResult(Intent intent, int index) {
105 String result = intent.getStringExtra(SUNSPIDER_RESULT);
106 mTotal = intent.getDoubleExtra(SUNSPIDER_TOTAL, 0.0);
108 if (result == null) {
109 Log.e(TAG, "Weird! cannot find SunSpiderInfo");
112 mJSResults[index] = result;
115 String formatted_result = intent.getStringExtra(SUNSPIDER_FORMATTED_RESULT);
116 if (result == null) {
117 Log.e(TAG, "Weird! cannot find SunSpiderInfo for formatted");
120 mFormattedResult = formatted_result;