summaryrefslogtreecommitdiffstats
path: root/benchmarks
diff options
context:
space:
mode:
authorJeff Hao <jeffhao@google.com>2014-06-26 20:27:24 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-06-26 17:56:55 +0000
commit42a6d80d91d8f33162b8946e6fc05e8b43833ca7 (patch)
tree505a01f51e399bfe13bdf66623fb14139f56a1d5 /benchmarks
parent236f03fdc589f800623f1830ff1aa2b640c6a1ef (diff)
parentf14b3694de2011c0c44beac9e0f8b9871ba888db (diff)
downloadlibcore-42a6d80d91d8f33162b8946e6fc05e8b43833ca7.zip
libcore-42a6d80d91d8f33162b8946e6fc05e8b43833ca7.tar.gz
libcore-42a6d80d91d8f33162b8946e6fc05e8b43833ca7.tar.bz2
Merge "Expanded arraycopy function to deal with more types and updated benchmarking."
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/src/benchmarks/SystemArrayCopyBenchmark.java76
1 files changed, 68 insertions, 8 deletions
diff --git a/benchmarks/src/benchmarks/SystemArrayCopyBenchmark.java b/benchmarks/src/benchmarks/SystemArrayCopyBenchmark.java
index c22e819..5095ee1 100644
--- a/benchmarks/src/benchmarks/SystemArrayCopyBenchmark.java
+++ b/benchmarks/src/benchmarks/SystemArrayCopyBenchmark.java
@@ -24,17 +24,77 @@ public class SystemArrayCopyBenchmark extends SimpleBenchmark {
"2048", "4096", "8192", "16384", "32768", "65536", "131072", "262144"})
int arrayLength;
- // This copies a char array indirectly via String.getChars() as the
- // System.arraycopy() call site optimization currently works within
- // the core libraries only. Add direct System.arraycopy() benchmarks
- // (including ones for other primitive types) later once this
- // limitation goes away.
- public void timeStringCharArrayCopy(int reps) {
+ // Provides benchmarking for different types of arrays using the arraycopy function.
+
+ public void timeSystemCharArrayCopy(int reps) {
final int len = arrayLength;
+ char[] src = new char[len];
char[] dst = new char[len];
- String str = new String(new char[len]);
for (int rep = 0; rep < reps; ++rep) {
- str.getChars(0, len, dst, 0);
+ System.arraycopy(src, 0, dst, 0, len);
+ }
+ }
+
+ public void timeSystemByteArrayCopy(int reps) {
+ final int len = arrayLength;
+ byte[] src = new byte[len];
+ byte[] dst = new byte[len];
+ for (int rep = 0; rep < reps; ++rep) {
+ System.arraycopy(src, 0, dst, 0, len);
+ }
+ }
+
+ public void timeSystemShortArrayCopy(int reps) {
+ final int len = arrayLength;
+ short[] src = new short[len];
+ short[] dst = new short[len];
+ for (int rep = 0; rep < reps; ++rep) {
+ System.arraycopy(src, 0, dst, 0, len);
+ }
+ }
+
+ public void timeSystemIntArrayCopy(int reps) {
+ final int len = arrayLength;
+ int[] src = new int[len];
+ int[] dst = new int[len];
+ for (int rep = 0; rep < reps; ++rep) {
+ System.arraycopy(src, 0, dst, 0, len);
+ }
+ }
+
+ public void timeSystemLongArrayCopy(int reps) {
+ final int len = arrayLength;
+ long[] src = new long[len];
+ long[] dst = new long[len];
+ for (int rep = 0; rep < reps; ++rep) {
+ System.arraycopy(src, 0, dst, 0, len);
+ }
+ }
+
+ public void timeSystemFloatArrayCopy(int reps) {
+ final int len = arrayLength;
+ float[] src = new float[len];
+ float[] dst = new float[len];
+ for (int rep = 0; rep < reps; ++rep) {
+ System.arraycopy(src, 0, dst, 0, len);
+ }
+ }
+
+ public void timeSystemDoubleArrayCopy(int reps) {
+ final int len = arrayLength;
+ double[] src = new double[len];
+ double[] dst = new double[len];
+ for (int rep = 0; rep < reps; ++rep) {
+ System.arraycopy(src, 0, dst, 0, len);
+ }
+ }
+
+ public void timeSystemBooleanArrayCopy(int reps) {
+ final int len = arrayLength;
+ boolean[] src = new boolean[len];
+ boolean[] dst = new boolean[len];
+ for (int rep = 0; rep < reps; ++rep) {
+ System.arraycopy(src, 0, dst, 0, len);
}
}
}