summaryrefslogtreecommitdiffstats
path: root/vm/test
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-18 22:20:24 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-18 22:20:24 -0700
commit99409883d9c4c0ffb49b070ce307bb33a9dfe9f1 (patch)
tree47fa49e57ca43a07d37839ef5db35b705ec738fe /vm/test
parent27e65e506369aa7eaca3e92a77631af63079ebd6 (diff)
downloadandroid_dalvik-99409883d9c4c0ffb49b070ce307bb33a9dfe9f1.tar.gz
android_dalvik-99409883d9c4c0ffb49b070ce307bb33a9dfe9f1.tar.bz2
android_dalvik-99409883d9c4c0ffb49b070ce307bb33a9dfe9f1.zip
auto import //branches/master/...@140412
Diffstat (limited to 'vm/test')
-rw-r--r--vm/test/AtomicSpeed.c115
-rw-r--r--vm/test/Test.h2
2 files changed, 117 insertions, 0 deletions
diff --git a/vm/test/AtomicSpeed.c b/vm/test/AtomicSpeed.c
new file mode 100644
index 000000000..e2ffbeff3
--- /dev/null
+++ b/vm/test/AtomicSpeed.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * 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.
+ */
+
+/*
+ * Atomic operation performance test.
+ */
+#include "Dalvik.h"
+
+//#define TRIVIAL_COMPARE /* do something simple instead of an atomic op */
+
+/*
+ * Perform operation. Returns elapsed time.
+ */
+u8 dvmTestAtomicSpeedSub(int repeatCount)
+{
+ static int value = 7;
+ int* valuePtr = &value;
+ u8 start, end;
+ int i;
+
+#ifdef TRIVIAL_COMPARE
+ /* init to arg value so compiler can't pre-determine result */
+ int j = repeatCount;
+#endif
+
+ assert((repeatCount % 10) == 0);
+
+ start = dvmGetRelativeTimeNsec();
+
+ for (i = repeatCount / 10; i != 0; i--) {
+#ifdef TRIVIAL_COMPARE
+ // integer add (Dream: 3.4ns -- THUMB has 10 adds, ARM condenses)
+ j += i; j += i; j += i; j += i; j += i;
+ j += i; j += i; j += i; j += i; j += i;
+#else
+ // succeed 10x (Dream: 155.9ns)
+ ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 7, 7);
+
+ // fail 10x (Dream: 158.5ns)
+ /*
+ ATOMIC_CMP_SWAP(valuePtr, 6, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 6, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 6, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 6, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 6, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 6, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 6, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 6, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 6, 7);
+ ATOMIC_CMP_SWAP(valuePtr, 6, 7);
+ */
+#endif
+ }
+
+ end = dvmGetRelativeTimeNsec();
+
+#ifdef TRIVIAL_COMPARE
+ /* use value so compiler can't eliminate it */
+ dvmFprintf(stdout, "%d\n", j);
+#else
+ dvmFprintf(stdout, ".");
+ fflush(stdout); // not quite right if they intercepted fprintf
+#endif
+ return end - start;
+}
+
+/*
+ * Control loop.
+ */
+bool dvmTestAtomicSpeed(void)
+{
+ static const int kIterations = 10;
+ static const int kRepeatCount = 5 * 1000 * 1000;
+ static const int kDelay = 500 * 1000;
+ u8 results[kIterations];
+ int i;
+
+ for (i = 0; i < kIterations; i++) {
+ results[i] = dvmTestAtomicSpeedSub(kRepeatCount);
+ usleep(kDelay);
+ }
+
+ dvmFprintf(stdout, "\n");
+ dvmFprintf(stdout, "Atomic speed test results (%d per iteration):\n",
+ kRepeatCount);
+ for (i = 0; i < kIterations; i++) {
+ dvmFprintf(stdout,
+ " %2d: %.3fns\n", i, (double) results[i] / kRepeatCount);
+ }
+
+ return true;
+}
+
diff --git a/vm/test/Test.h b/vm/test/Test.h
index a6b54a5a6..ce47aae07 100644
--- a/vm/test/Test.h
+++ b/vm/test/Test.h
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
/*
* Internal unit tests.
*/
@@ -20,5 +21,6 @@
#define _DALVIK_TEST_TEST
bool dvmTestHash(void);
+bool dvmTestAtomicSpeed(void);
#endif /*_DALVIK_TEST_TEST*/