summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2011-04-18 16:04:26 -0700
committerJesse Wilson <jessewilson@google.com>2011-04-18 16:14:59 -0700
commit541ea61e7ee10b5bace0a3481511864fec74e6e8 (patch)
tree6c0c6896462c47cd7028eb00850ffae02f4cbc48 /tests
parent70bd7ff71f304620f9a2ac24c4475ad234a0c2be (diff)
downloadandroid_dalvik-541ea61e7ee10b5bace0a3481511864fec74e6e8.tar.gz
android_dalvik-541ea61e7ee10b5bace0a3481511864fec74e6e8.tar.bz2
android_dalvik-541ea61e7ee10b5bace0a3481511864fec74e6e8.zip
Adjust basis against which enum performance is compared.
The new basis assumes how much work Enum.valueOf() needs to do and checks that it does just that and little else. It makes no attempt to compute a general speed of the VM or to compare ratios of unrelated operations. Change-Id: I0014fb37cfcf36016e72e97ca182e3836044782e
Diffstat (limited to 'tests')
-rw-r--r--tests/055-enum-performance/expected.txt2
-rw-r--r--tests/055-enum-performance/src/Main.java72
2 files changed, 35 insertions, 39 deletions
diff --git a/tests/055-enum-performance/expected.txt b/tests/055-enum-performance/expected.txt
index d81c19449..ceb6bc4ac 100644
--- a/tests/055-enum-performance/expected.txt
+++ b/tests/055-enum-performance/expected.txt
@@ -5,7 +5,7 @@ NINE
FIVE
TWELVE
SamePackagePublicEnum
-basis: performed 40000 iterations
+basis: performed 10000 iterations
test1: performed 10000 iterations
test2: performed 10000 iterations
test3: performed 10000 iterations
diff --git a/tests/055-enum-performance/src/Main.java b/tests/055-enum-performance/src/Main.java
index 64d03ebad..43f45f1a8 100644
--- a/tests/055-enum-performance/src/Main.java
+++ b/tests/055-enum-performance/src/Main.java
@@ -19,7 +19,7 @@ public class Main {
long time2 = System.nanoTime();
int count3 = test3(500);
long time3 = System.nanoTime();
- int count4 = basis(2000);
+ int count4 = basis(500);
long time4 = System.nanoTime();
System.out.println("basis: performed " + count4 + " iterations");
@@ -33,7 +33,7 @@ public class Main {
double basisMsec = (time4 - time3) / (double) count4 / 1000000;
double avg = (msec1 + msec2 + msec3) / 3;
- if (avg < (basisMsec * 25)) {
+ if (avg < (basisMsec * 10)) {
System.out.println("Timing is acceptable.");
} else {
System.out.println("Iterations are taking too long!");
@@ -67,50 +67,46 @@ public class Main {
System.out.println(Enum.valueOf(c, "ZERO").getClass().getName());
}
+ static final String[] BASIS_COMPARE_ARRAY = {
+ "ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT",
+ "NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN",
+ "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN"
+ };
+
static public int basis(int iters) {
- /*
- * The basis time is the time taken to call a static method
- * passing two arguments, which in turn accesses a static
- * variable, compares a string, and does a little trivial math
- * and a trivial comparison. (That is, this is a mini
- * "omnibus" performance metric.) This is clearly going to be
- * much faster than Enum.valueOf(), which is why we multiply
- * the time before testing.
- */
for (int i = iters; i > 0; i--) {
- basisCall(i, "aname");
- basisCall(i, "bname");
- basisCall(i, "cname");
- basisCall(i, "dname");
- basisCall(i, "ename");
- basisCall(i, "fname");
- basisCall(i, "gname");
- basisCall(i, "hname");
- basisCall(i, "iname");
- basisCall(i, "jname");
- basisCall(i, "kname");
- basisCall(i, "lname");
- basisCall(i, "mname");
- basisCall(i, "nname");
- basisCall(i, "oname");
- basisCall(i, "pname");
- basisCall(i, "qname");
- basisCall(i, "rname");
- basisCall(i, "sname");
- basisCall(i, "tname");
+ basisValueOf("ZERO");
+ basisValueOf("ONE");
+ basisValueOf("TWO");
+ basisValueOf("THREE");
+ basisValueOf("FOUR");
+ basisValueOf("FIVE");
+ basisValueOf("SIX");
+ basisValueOf("SEVEN");
+ basisValueOf("EIGHT");
+ basisValueOf("NINE");
+ basisValueOf("TEN");
+ basisValueOf("ELEVEN");
+ basisValueOf("TWELVE");
+ basisValueOf("THIRTEEN");
+ basisValueOf("FOURTEEN");
+ basisValueOf("FIFTEEN");
+ basisValueOf("SIXTEEN");
+ basisValueOf("SEVENTEEN");
+ basisValueOf("EIGHTEEN");
+ basisValueOf("NINETEEN");
}
return iters * 20;
}
- static public int basisCall(int i, String name) {
- int compare = name.compareTo("fuzzbot");
-
- if (i < (basisTestValue * compare)) {
- return basisTestValue;
- } else {
- return i;
+ static String basisValueOf(String key) {
+ for (String s : BASIS_COMPARE_ARRAY) {
+ if (s.equals(key)) {
+ return s;
+ }
}
+ throw new IllegalArgumentException();
}
static public int test1(int iters) {