diff options
author | jeffhao <jeffhao@google.com> | 2011-09-29 17:41:15 -0700 |
---|---|---|
committer | jeffhao <jeffhao@google.com> | 2011-09-29 17:41:15 -0700 |
commit | 5d1ac920fdaef5d4ec8f66bb734488cd9660b024 (patch) | |
tree | dd372f306ab70f4c86759869b1f74eca62ff6f2b /test/055-enum-performance | |
parent | c31664f3d82e6cd68275a529a8a73f067a52e8be (diff) | |
download | art-5d1ac920fdaef5d4ec8f66bb734488cd9660b024.tar.gz art-5d1ac920fdaef5d4ec8f66bb734488cd9660b024.tar.bz2 art-5d1ac920fdaef5d4ec8f66bb734488cd9660b024.zip |
Adding old unit tests to test suite.
These tests are copied straight over. They'll still run, but they're
using the old system.
Change-Id: If494519e52ddf858a9febfc55bdae830468cb3c8
Diffstat (limited to 'test/055-enum-performance')
-rw-r--r-- | test/055-enum-performance/expected.txt | 12 | ||||
-rw-r--r-- | test/055-enum-performance/info.txt | 2 | ||||
-rw-r--r-- | test/055-enum-performance/src/Main.java | 195 | ||||
-rw-r--r-- | test/055-enum-performance/src/SamePackagePrivateEnum.java | 5 | ||||
-rw-r--r-- | test/055-enum-performance/src/SamePackagePublicEnum.java | 5 | ||||
-rw-r--r-- | test/055-enum-performance/src/otherpackage/OtherPackagePublicEnum.java | 7 |
6 files changed, 226 insertions, 0 deletions
diff --git a/test/055-enum-performance/expected.txt b/test/055-enum-performance/expected.txt new file mode 100644 index 0000000000..ceb6bc4ac2 --- /dev/null +++ b/test/055-enum-performance/expected.txt @@ -0,0 +1,12 @@ +FOUR +ONE +FOURTEEN +NINE +FIVE +TWELVE +SamePackagePublicEnum +basis: performed 10000 iterations +test1: performed 10000 iterations +test2: performed 10000 iterations +test3: performed 10000 iterations +Timing is acceptable. diff --git a/test/055-enum-performance/info.txt b/test/055-enum-performance/info.txt new file mode 100644 index 0000000000..2ea1b9d958 --- /dev/null +++ b/test/055-enum-performance/info.txt @@ -0,0 +1,2 @@ +This is a performance test of Enum.valueOf(). To see the numbers, invoke +this test with the "--timing" option. diff --git a/test/055-enum-performance/src/Main.java b/test/055-enum-performance/src/Main.java new file mode 100644 index 0000000000..43f45f1a8b --- /dev/null +++ b/test/055-enum-performance/src/Main.java @@ -0,0 +1,195 @@ +import otherpackage.OtherPackagePublicEnum; + +public class Main { + /** used by {@link #basisCall} */ + static private int basisTestValue = 12; + + static public void main(String[] args) throws Exception { + boolean timing = (args.length >= 1) && args[0].equals("--timing"); + run(timing); + } + + static public void run(boolean timing) { + preTest(); + + long time0 = System.nanoTime(); + int count1 = test1(500); + long time1 = System.nanoTime(); + int count2 = test2(500); + long time2 = System.nanoTime(); + int count3 = test3(500); + long time3 = System.nanoTime(); + int count4 = basis(500); + long time4 = System.nanoTime(); + + System.out.println("basis: performed " + count4 + " iterations"); + System.out.println("test1: performed " + count1 + " iterations"); + System.out.println("test2: performed " + count2 + " iterations"); + System.out.println("test3: performed " + count3 + " iterations"); + + double msec1 = (time1 - time0) / (double) count1 / 1000000; + double msec2 = (time2 - time1) / (double) count2 / 1000000; + double msec3 = (time3 - time2) / (double) count3 / 1000000; + double basisMsec = (time4 - time3) / (double) count4 / 1000000; + + double avg = (msec1 + msec2 + msec3) / 3; + if (avg < (basisMsec * 10)) { + System.out.println("Timing is acceptable."); + } else { + System.out.println("Iterations are taking too long!"); + timing = true; + } + + if (timing) { + System.out.printf("basis time: %.3g msec\n", basisMsec); + System.out.printf("test1: %.3g msec per iteration\n", msec1); + System.out.printf("test2: %.3g msec per iteration\n", msec2); + System.out.printf("test3: %.3g msec per iteration\n", msec3); + } + + } + + static public void preTest() { + /* + * This is meant to ensure that the basic enum functionality + * really is working. + */ + + Class<SamePackagePublicEnum> c = SamePackagePublicEnum.class; + + System.out.println(Enum.valueOf(c, "FOUR")); + System.out.println(Enum.valueOf(c, "ONE")); + System.out.println(Enum.valueOf(c, "FOURTEEN")); + System.out.println(Enum.valueOf(c, "NINE")); + System.out.println(Enum.valueOf(c, "FIVE")); + System.out.println(Enum.valueOf(c, "TWELVE")); + + 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) { + for (int i = iters; i > 0; i--) { + 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 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) { + Class<SamePackagePublicEnum> c = SamePackagePublicEnum.class; + for (int i = iters; i > 0; i--) { + Enum.valueOf(c, "ZERO"); + Enum.valueOf(c, "ONE"); + Enum.valueOf(c, "TWO"); + Enum.valueOf(c, "THREE"); + Enum.valueOf(c, "FOUR"); + Enum.valueOf(c, "FIVE"); + Enum.valueOf(c, "SIX"); + Enum.valueOf(c, "SEVEN"); + Enum.valueOf(c, "EIGHT"); + Enum.valueOf(c, "NINE"); + Enum.valueOf(c, "TEN"); + Enum.valueOf(c, "ELEVEN"); + Enum.valueOf(c, "TWELVE"); + Enum.valueOf(c, "THIRTEEN"); + Enum.valueOf(c, "FOURTEEN"); + Enum.valueOf(c, "FIFTEEN"); + Enum.valueOf(c, "SIXTEEN"); + Enum.valueOf(c, "SEVENTEEN"); + Enum.valueOf(c, "EIGHTEEN"); + Enum.valueOf(c, "NINETEEN"); + } + + return iters * 20; + } + + static public int test2(int iters) { + Class<SamePackagePrivateEnum> c = SamePackagePrivateEnum.class; + for (int i = iters; i > 0; i--) { + Enum.valueOf(c, "ZERO"); + Enum.valueOf(c, "ONE"); + Enum.valueOf(c, "TWO"); + Enum.valueOf(c, "THREE"); + Enum.valueOf(c, "FOUR"); + Enum.valueOf(c, "FIVE"); + Enum.valueOf(c, "SIX"); + Enum.valueOf(c, "SEVEN"); + Enum.valueOf(c, "EIGHT"); + Enum.valueOf(c, "NINE"); + Enum.valueOf(c, "TEN"); + Enum.valueOf(c, "ELEVEN"); + Enum.valueOf(c, "TWELVE"); + Enum.valueOf(c, "THIRTEEN"); + Enum.valueOf(c, "FOURTEEN"); + Enum.valueOf(c, "FIFTEEN"); + Enum.valueOf(c, "SIXTEEN"); + Enum.valueOf(c, "SEVENTEEN"); + Enum.valueOf(c, "EIGHTEEN"); + Enum.valueOf(c, "NINETEEN"); + } + + return iters * 20; + } + + static public int test3(int iters) { + Class<OtherPackagePublicEnum> c = OtherPackagePublicEnum.class; + for (int i = iters; i > 0; i--) { + Enum.valueOf(c, "ZERO"); + Enum.valueOf(c, "ONE"); + Enum.valueOf(c, "TWO"); + Enum.valueOf(c, "THREE"); + Enum.valueOf(c, "FOUR"); + Enum.valueOf(c, "FIVE"); + Enum.valueOf(c, "SIX"); + Enum.valueOf(c, "SEVEN"); + Enum.valueOf(c, "EIGHT"); + Enum.valueOf(c, "NINE"); + Enum.valueOf(c, "TEN"); + Enum.valueOf(c, "ELEVEN"); + Enum.valueOf(c, "TWELVE"); + Enum.valueOf(c, "THIRTEEN"); + Enum.valueOf(c, "FOURTEEN"); + Enum.valueOf(c, "FIFTEEN"); + Enum.valueOf(c, "SIXTEEN"); + Enum.valueOf(c, "SEVENTEEN"); + Enum.valueOf(c, "EIGHTEEN"); + Enum.valueOf(c, "NINETEEN"); + } + + return iters * 20; + } +} diff --git a/test/055-enum-performance/src/SamePackagePrivateEnum.java b/test/055-enum-performance/src/SamePackagePrivateEnum.java new file mode 100644 index 0000000000..b6759f69fa --- /dev/null +++ b/test/055-enum-performance/src/SamePackagePrivateEnum.java @@ -0,0 +1,5 @@ +/*package*/ enum SamePackagePrivateEnum { + ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, + TEN, ELEVEN, TWELVE, THIRTEEN, FOURTEEN, FIFTEEN, SIXTEEN, + SEVENTEEN, EIGHTEEN, NINETEEN; +} diff --git a/test/055-enum-performance/src/SamePackagePublicEnum.java b/test/055-enum-performance/src/SamePackagePublicEnum.java new file mode 100644 index 0000000000..3a1c230461 --- /dev/null +++ b/test/055-enum-performance/src/SamePackagePublicEnum.java @@ -0,0 +1,5 @@ +public enum SamePackagePublicEnum { + ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, + TEN, ELEVEN, TWELVE, THIRTEEN, FOURTEEN, FIFTEEN, SIXTEEN, + SEVENTEEN, EIGHTEEN, NINETEEN; +} diff --git a/test/055-enum-performance/src/otherpackage/OtherPackagePublicEnum.java b/test/055-enum-performance/src/otherpackage/OtherPackagePublicEnum.java new file mode 100644 index 0000000000..4ef4d78788 --- /dev/null +++ b/test/055-enum-performance/src/otherpackage/OtherPackagePublicEnum.java @@ -0,0 +1,7 @@ +package otherpackage; + +public enum OtherPackagePublicEnum { + ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, + TEN, ELEVEN, TWELVE, THIRTEEN, FOURTEEN, FIFTEEN, SIXTEEN, + SEVENTEEN, EIGHTEEN, NINETEEN; +} |