add benchmark

This commit is contained in:
Shaojin Wen 2025-01-08 08:23:21 +08:00
parent 967694f69e
commit 8aae88ee06
2 changed files with 32 additions and 12 deletions

View File

@ -44,7 +44,7 @@ import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@State(Scope.Thread)
@Warmup(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Fork(3)
public class Integers {
@ -106,13 +106,6 @@ public class Integers {
}
}
@Benchmark
public void toHexString(Blackhole bh) {
for (int i : intsBig) {
bh.consume(Integer.toHexString(i));
}
}
/** Performs toString on large values, roughly 10 digits. */
@Benchmark
public void toStringBig(Blackhole bh) {
@ -121,6 +114,27 @@ public class Integers {
}
}
@Benchmark
public void toHexStringTiny(Blackhole bh) {
for (int i : intsTiny) {
bh.consume(Integer.toHexString(i));
}
}
@Benchmark
public void toHexStringSmall(Blackhole bh) {
for (int i : intsSmall) {
bh.consume(Integer.toHexString(i));
}
}
@Benchmark
public void toHexStringBig(Blackhole bh) {
for (int i : intsBig) {
bh.consume(Integer.toHexString(i));
}
}
/** Performs expand on small values */
@Benchmark
public void expand(Blackhole bh) {

View File

@ -87,17 +87,23 @@ public class Longs {
/** Performs toString on large values, around 10 digits. */
@Benchmark
public void toHexString(Blackhole bh) {
public void toStringBig(Blackhole bh) {
for (long value : longArrayBig) {
bh.consume(Long.toString(value));
}
}
@Benchmark
public void toHexStringSmall(Blackhole bh) {
for (long value : longArraySmall) {
bh.consume(Long.toHexString(value));
}
}
/** Performs toString on large values, around 10 digits. */
@Benchmark
public void toStringBig(Blackhole bh) {
public void toHexStringBig(Blackhole bh) {
for (long value : longArrayBig) {
bh.consume(Long.toString(value));
bh.consume(Long.toHexString(value));
}
}