summaryrefslogtreecommitdiffstats
path: root/benchmarks
diff options
context:
space:
mode:
authorEmma Meersman <emeersman@google.com>2014-06-18 11:44:35 -0700
committerEmma Meersman <emeersman@google.com>2014-06-23 10:37:15 -0700
commitf14b3694de2011c0c44beac9e0f8b9871ba888db (patch)
tree4cc49a6b139891976bb632debdbdfe3b51cc2589 /benchmarks
parent2b9311770bc531f15edb43f382696f3954a7c4e8 (diff)
downloadlibcore-f14b3694de2011c0c44beac9e0f8b9871ba888db.zip
libcore-f14b3694de2011c0c44beac9e0f8b9871ba888db.tar.gz
libcore-f14b3694de2011c0c44beac9e0f8b9871ba888db.tar.bz2
Expanded arraycopy function to deal with more types and updated benchmarking.
Runs 48% faster on average for short arrays of length 16-128, depending on the type. Defaults to native code for longer arrays. Bug: 7103825 Change-Id: I70ca8f4a379600917e5bc103364af0637f18e03a
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);
}
}
}