Update examples

This commit is contained in:
2019-12-29 12:02:00 +01:00
parent c4477aca38
commit ecdd16363a
5 changed files with 75 additions and 26 deletions

View File

@ -31,7 +31,7 @@ public class Main {
return String.format("Object %s", o);
}
private static long[] runNTimes(int numberOfRuns, Object[] toTest, Consumer<? super Object> code) {
private static <T> long[] runNTimes(int numberOfRuns, T[] toTest, Consumer<T> code) {
long runs[] = new long[numberOfRuns];
for (int i = 0; i < numberOfRuns; i++) {
long startTime = System.nanoTime();
@ -52,7 +52,7 @@ public class Main {
.orWhen(Byte.class::isInstance, b -> "byte " + b)
.orWhen(Double.class::isInstance, d -> "double " + d)
.orWhen(String.class::isInstance, s -> "String " + s)
.otherwise(o -> "Object " + o);
.otherwise(o -> String.format("Object %s", o));
final int nRuns = 100000;
final Statistics formatObjectStats = Statistics.from(runNTimes(nRuns, toTest, Main::formatObject));