1/* 2 * Copyright (C) 2010 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package benchmarks; 18 19import com.google.caliper.Param; 20import com.google.caliper.Runner; 21import com.google.caliper.SimpleBenchmark; 22 23import java.util.Map; 24import java.util.HashMap; 25 26/** 27 * Is there a performance reason to "Prefer virtual over interface", as the 28 * Android documentation once claimed? 29 */ 30public class VirtualVersusInterfaceBenchmark extends SimpleBenchmark { 31 public void timeMapPut(int reps) { 32 Map<String, String> map = new HashMap<String, String>(); 33 for (int i = 0; i < reps; ++i) { 34 map.put("hello", "world"); 35 } 36 } 37 public void timeHashMapPut(int reps) { 38 HashMap<String, String> map = new HashMap<String, String>(); 39 for (int i = 0; i < reps; ++i) { 40 map.put("hello", "world"); 41 } 42 } 43} 44