1550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth/*
2550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth * Copyright (C) 2016 Google Inc.
3550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth *
4550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth * Licensed under the Apache License, Version 2.0 (the "License");
5550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth * you may not use this file except in compliance with the License.
6550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth * You may obtain a copy of the License at
7550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth *
8550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth * http://www.apache.org/licenses/LICENSE-2.0
9550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth *
10550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth * Unless required by applicable law or agreed to in writing, software
11550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth * distributed under the License is distributed on an "AS IS" BASIS,
12550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth * See the License for the specific language governing permissions and
14550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth * limitations under the License.
15550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth */
16550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth
17550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworthpackage benchmarks;
18550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth
19550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth/**
20550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth * How long does it take to access a string in the dex cache?
21550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth */
22550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworthpublic class StringDexCacheBenchmark {
23550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth    public int timeStringDexCacheAccess(int reps) {
24550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth        int v = 0;
25550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth        for (int rep = 0; rep < reps; ++rep) {
26550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth          // Deliberately obscured to make optimizations less likely.
27550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth          String s = (rep >= 0) ? "hello, world!" : null;
28550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth          v += s.length();
29550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth        }
30550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth        return v;
31550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth    }
32550f405fe9eee8ba8757cbc969fae3b89061b39aChristina Wadsworth}
33