8271840: Add simple Integer.toString microbenchmarks

Reviewed-by: shade
This commit is contained in:
Claes Redestad 2021-08-05 14:46:38 +00:00
parent 18dd4d469d
commit 55bd52a142
2 changed files with 40 additions and 10 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/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
@ -24,13 +24,15 @@ package org.openjdk.bench.java.lang;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
import java.util.concurrent.TimeUnit;
@ -38,6 +40,9 @@ import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@State(Scope.Thread)
@Warmup(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Fork(3)
public class Longs {
@Param("500")
@ -56,18 +61,16 @@ public class Longs {
}
}
/** Performs toString on a bunch of java.lang.Long:s, all with small values, just a couple of digits. */
/** Performs toString on small values, just a couple of digits. */
@Benchmark
@Threads(Threads.MAX)
public void toStringSmall(Blackhole bh) {
for (long value : longArraySmall) {
bh.consume(Long.toString(value));
}
}
/** Performs toString on a bunch of java.lang.Long:s, all with large values, around 10 digits. */
/** Performs toString on large values, around 10 digits. */
@Benchmark
@Threads(Threads.MAX)
public void toStringBig(Blackhole bh) {
for (long value : longArrayBig) {
bh.consume(Long.toString(value));
@ -80,7 +83,6 @@ public class Longs {
public int innerLoops = 1500;
@Benchmark
@Threads(Threads.MAX)
public long repetitiveSubtraction() {
long x = 127, dx = 0;