From e715fe64e96acb6131af937d0c8bba2537ea13f4 Mon Sep 17 00:00:00 2001 From: Ningsheng Jian Date: Tue, 7 Nov 2017 18:38:01 +0800 Subject: Port and add more cases. 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 Signed-off-by: Yang Zhang Signed-off-by: Ningsheng Jian Change-Id: I514658696b63e468158325be3b84494553773705 --- .../org/linaro/benchmarks/micro/HashMapBench.java | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/main/java/org/linaro/benchmarks/micro/HashMapBench.java (limited to 'src/main/java/org/linaro/benchmarks/micro/HashMapBench.java') 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 map = new HashMap(); + + @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 entry : map.entrySet()) { + keySum += entry.getKey(); + valueSum += entry.getValue(); + } + } +} -- cgit v1.2.3