summaryrefslogtreecommitdiff
path: root/src/main/java/org/linaro/benchmarks/micro/HashMapBench.java
diff options
context:
space:
mode:
authorNingsheng Jian <ningsheng.jian@linaro.org>2017-11-07 18:38:01 +0800
committerNingsheng Jian <ningsheng.jian@linaro.org>2017-11-16 09:46:55 +0800
commite715fe64e96acb6131af937d0c8bba2537ea13f4 (patch)
tree702384eb404c3fd6acbbc3321261847e9fc27398 /src/main/java/org/linaro/benchmarks/micro/HashMapBench.java
parent3811e9930ddb1d2b3a1463ad6c876af324331335 (diff)
Port and add more cases.HEADmaster
1. Port benchmark cases from art-testing. 2. Add some more benchmarks for basic OPs. 3. Fix some jmh result variance. Signed-off-by: Zhongwei Yao <zhongwei.yao@linaro.org> Signed-off-by: Yang Zhang <yang.zhang@linaro.org> Signed-off-by: Ningsheng Jian <ningsheng.jian@linaro.org> Change-Id: I514658696b63e468158325be3b84494553773705
Diffstat (limited to 'src/main/java/org/linaro/benchmarks/micro/HashMapBench.java')
-rw-r--r--src/main/java/org/linaro/benchmarks/micro/HashMapBench.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/main/java/org/linaro/benchmarks/micro/HashMapBench.java b/src/main/java/org/linaro/benchmarks/micro/HashMapBench.java
new file mode 100644
index 0000000..02ffe14
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/micro/HashMapBench.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2015, Linaro Limited. Ported to Java from:
+ * http://browserbench.org/JetStream/sources/hash-map.js
+ *
+ * Description: A benchmark case for hash map
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE below for additional
+ * information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+/******* NOTICE *********
+
+ Apache Harmony
+ Copyright 2006, 2010 The Apache Software Foundation.
+
+ This product includes software developed at
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Portions of Apache Harmony were originally developed by
+ Intel Corporation and are licensed to the Apache Software
+ Foundation under the "Software Grant and Corporate Contribution
+ License Agreement" and for which the following copyright notices
+ apply
+ (C) Copyright 2005 Intel Corporation
+ (C) Copyright 2005-2006 Intel Corporation
+ (C) Copyright 2006 Intel Corporation
+
+
+ The following copyright notice(s) were affixed to portions of the code
+ with which this file is now or was at one time distributed
+ and are placed here unaltered.
+
+ (C) Copyright 1997,2004 International Business Machines Corporation.
+ All rights reserved.
+
+ (C) Copyright IBM Corp. 2003.
+
+
+ This software contains code derived from UNIX V7, Copyright(C)
+ Caldera International Inc.
+
+ ************************/
+
+package org.linaro.benchmarks.micro;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+public class HashMapBench {
+
+ private static final int COUNT = 5000;
+ private static final int resultExpect = 1050000;
+ private static final long keySumExpect = 12497500;
+ private static final int valueSumExpect = 210000;
+ private int result = 0;
+ private long keySum = 0;
+ private int valueSum = 0;
+
+ private Map<Integer, Integer> map = new HashMap<Integer, Integer>();
+
+ @Benchmark
+ public void jmhTimeTestHashMap() {
+ for (int j = 0; j < COUNT; j++) {
+ map.put(j, 42);
+ }
+
+ result = 0;
+ for (int k = 0; k < 5; k++) {
+ for (int j = 0; j < COUNT; j++) {
+ result += map.get(j);
+ }
+ }
+
+ keySum = 0;
+ valueSum = 0;
+ for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
+ keySum += entry.getKey();
+ valueSum += entry.getValue();
+ }
+ }
+}