Open dylanjtuttle opened 1 month ago
The following code would fix the crash and also ensure both lines are properly aligned no matter the length of the benchmark name. It can probably be cleaned up further, but I thought I would include it just as a starting point:
// In net/adoptopenjdk/bumblebench/core/BumbleBench.java
if (verify()) {
String line1_prefix = " " + _name + " score: ";
String line2_prefix = " uncertainty: ";
if (line1_prefix.length() < line2_prefix.length()) {
line1_prefix = " ".repeat(line2_prefix.length() - line1_prefix.length()) + line1_prefix;
} else if (line1_prefix.length() > line2_prefix.length()) {
line2_prefix = " ".repeat(line1_prefix.length() - line2_prefix.length()) + line2_prefix;
}
out().println("\n" + line1_prefix + String.format("%f",_maxPeak) + " (" + score(_maxPeak) + " " + logPoints(_maxPeak) + "%)");
out().println(line2_prefix + percentage(_uncertainty) + "%");
} else {
out().println("ERROR: failed verification.");
}
@dylanjtuttle Pull Request would be welcome!
When running a microbenchmark with a benchmark class name of 5 characters, the following runtime exception occurs:
This exception occurs in
BumbleBench.run()
, where the lines reporting the score and uncertainty at the end of the run are constructed and printed.In order to ensure an aesthetic alignment of the two lines, a number of spaces are sometimes added to the beginning of the second line, as in this example:
However, the line of code which produces the correct number of spaces assumes that the name of the benchmark is at least 6 characters:
Since
%0s
is not a valid string format specifier, if the class name is 5 characters long, we get a crash. Although obviously less significant, if the class name is 4 characters or less, we don't get a crash, but we also don't get the alignment that this code intends to produce. For example, here is the output for a benchmark with a 4 character name,Test
:The following simple benchmark can reproduce this crash: