mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8306075: Micro-optimize Enum.hashCode
Co-authored-by: Aleksey Shipilev <shade@openjdk.org> Reviewed-by: redestad, shade, rriggs, liach, apangin, jvernee
This commit is contained in:
parent
fdaabd6eec
commit
3da987adac
2 changed files with 73 additions and 1 deletions
55
test/micro/org/openjdk/bench/java/lang/EnumHashCode.java
Normal file
55
test/micro/org/openjdk/bench/java/lang/EnumHashCode.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package org.openjdk.bench.java.lang;
|
||||
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@State(Scope.Thread)
|
||||
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
|
||||
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
|
||||
@Fork(3)
|
||||
public class EnumHashCode {
|
||||
|
||||
enum E {
|
||||
A, B, C;
|
||||
}
|
||||
|
||||
Enum e = E.A;
|
||||
|
||||
@Benchmark
|
||||
public int constant() {
|
||||
// Tests that hash code is constant-foldable
|
||||
return E.A.hashCode();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public int field() {
|
||||
// Tests that hash code is efficient
|
||||
return e.hashCode();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue