blob: 297cbb04f11328683636888b507731dc9afc2ebe [file] [log] [blame]
Jeff Hao88474b42013-10-23 16:24:40 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
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
17import java.util.Map;
18import java.util.HashMap;
19
Andreas Gampe1c83cbc2014-07-22 18:52:29 -070020public class Main {
Jeff Hao88474b42013-10-23 16:24:40 -070021
22 public static long test_virtual(HashMap map) {
23 Integer intobj = new Integer(0);
24 String s = "asdf";
25 long start = System.currentTimeMillis();
Dave Allison648d7112014-07-25 16:15:27 -070026 for (int i = 0; i < 10000; i++) {
Jeff Hao88474b42013-10-23 16:24:40 -070027 map.put(intobj, s);
28 }
29 long end = System.currentTimeMillis();
30 return (end - start);
31 }
32
33 public static long test_interface(Map map) {
34 Integer intobj = new Integer(0);
35 String s = "asdf";
36 long start = System.currentTimeMillis();
Dave Allison648d7112014-07-25 16:15:27 -070037 for (int i = 0; i < 10000; i++) {
Jeff Hao88474b42013-10-23 16:24:40 -070038 map.put(intobj, s);
39 }
40 long end = System.currentTimeMillis();
41 return (end - start);
42 }
43
44 public static void main(String[] args) {
45 HashMap hashmap = new HashMap();
46 long elapsed = test_virtual(hashmap);
Andreas Gampe1c83cbc2014-07-22 18:52:29 -070047 System.out.println("test_virtual done");
Jeff Hao88474b42013-10-23 16:24:40 -070048 hashmap.clear();
49
50 elapsed = test_interface(hashmap);
Andreas Gampe1c83cbc2014-07-22 18:52:29 -070051 System.out.println("test_interface done");
Jeff Hao88474b42013-10-23 16:24:40 -070052 }
53}