diff options
author | Jeff Hao <jeffhao@google.com> | 2014-06-26 20:37:07 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-06-26 20:37:07 +0000 |
commit | fd2ca69a09c4efe76244f2fcf2612a0ff8b82d08 (patch) | |
tree | da65eedf502a3d5bdc92c95e860e36307408e35e /benchmarks | |
parent | ca6fa02b3f2bd5d9d30143e9318601258846097e (diff) | |
parent | 42a6d80d91d8f33162b8946e6fc05e8b43833ca7 (diff) | |
download | libcore-fd2ca69a09c4efe76244f2fcf2612a0ff8b82d08.zip libcore-fd2ca69a09c4efe76244f2fcf2612a0ff8b82d08.tar.gz libcore-fd2ca69a09c4efe76244f2fcf2612a0ff8b82d08.tar.bz2 |
am 42a6d80d: Merge "Expanded arraycopy function to deal with more types and updated benchmarking."
* commit '42a6d80d91d8f33162b8946e6fc05e8b43833ca7':
Expanded arraycopy function to deal with more types and updated benchmarking.
Diffstat (limited to 'benchmarks')
-rw-r--r-- | benchmarks/src/benchmarks/SystemArrayCopyBenchmark.java | 76 |
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); } } } |