diff options
author | Christina Wadsworth <cwadsworth@google.com> | 2016-08-25 15:36:35 -0700 |
---|---|---|
committer | Christina Wadsworth <cwadsworth@google.com> | 2016-08-26 15:13:22 -0700 |
commit | 550f405fe9eee8ba8757cbc969fae3b89061b39a (patch) | |
tree | 04551b249ed07ffae814432b26fe744edcba9843 /benchmarks | |
parent | 80c10512331c190311221a571ab100d5405c345b (diff) |
ART: Added benchmark for string dex cache
Added a benchmark for the string dex cache, measures how long the fast
path takes. In order to account for potential optimizations, I have
separated it into two different functions, one of which is called from a
loop so the code is no longer in the loop. Please subtract ~1.5ns from
the runtime per iteration as a result.
Change-Id: I77803ebf83b18b806288349e1e5b3d26ac215d84
Diffstat (limited to 'benchmarks')
-rw-r--r-- | benchmarks/src/benchmarks/StringDexCacheBenchmark.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/benchmarks/src/benchmarks/StringDexCacheBenchmark.java b/benchmarks/src/benchmarks/StringDexCacheBenchmark.java new file mode 100644 index 0000000000..ce72b4d90a --- /dev/null +++ b/benchmarks/src/benchmarks/StringDexCacheBenchmark.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2016 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; + +/** + * How long does it take to access a string in the dex cache? + */ +public class StringDexCacheBenchmark { + public int timeStringDexCacheAccess(int reps) { + int v = 0; + for (int rep = 0; rep < reps; ++rep) { + // Deliberately obscured to make optimizations less likely. + String s = (rep >= 0) ? "hello, world!" : null; + v += s.length(); + } + return v; + } +} |