diff options
author | Hiroshi Yamauchi <yamauchi@google.com> | 2013-08-21 16:27:11 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2013-11-05 17:09:44 -0800 |
commit | 9edc1d397e9de3d50cbebd550262a51a6926e924 (patch) | |
tree | c89a48815669c7ea95d5288c6d4a57fb759c4fa3 /benchmarks | |
parent | 30062035682a74a128223829b8e1c1a9fb5699ba (diff) | |
download | libcore-9edc1d397e9de3d50cbebd550262a51a6926e924.zip libcore-9edc1d397e9de3d50cbebd550262a51a6926e924.tar.gz libcore-9edc1d397e9de3d50cbebd550262a51a6926e924.tar.bz2 |
A char array copy optimization (libcore).
- Based on measurements, copy char by char for arrays of length <= 64.
- With this change, the Ritz MemAllocBench got ~25% faster on Nexus 4
and ~20% faster on host.
- This change only handles arraycopy calls in the core libraries and
char arrays with the rest future work.
Bug: 7103825
(cherry picked from commit a3eb10feba1c3479ad99ef5c5323d011a5365f4b)
Change-Id: Ic002ced3bc2f2a682cd4b8cec07ede990edd7463
Diffstat (limited to 'benchmarks')
-rw-r--r-- | benchmarks/src/benchmarks/SystemArrayCopyBenchmark.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/benchmarks/src/benchmarks/SystemArrayCopyBenchmark.java b/benchmarks/src/benchmarks/SystemArrayCopyBenchmark.java new file mode 100644 index 0000000..c22e819 --- /dev/null +++ b/benchmarks/src/benchmarks/SystemArrayCopyBenchmark.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2013 Google Inc. + * + * 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. + */ + +package benchmarks; + +import com.google.caliper.Param; +import com.google.caliper.SimpleBenchmark; + +public class SystemArrayCopyBenchmark extends SimpleBenchmark { + @Param({"2", "4", "8", "16", "32", "64", "128", "256", "512", "1024", + "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) { + final int len = arrayLength; + 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); + } + } +} |