aboutsummaryrefslogtreecommitdiff
path: root/benchmarks/java/src/main/java/com/google/protobuf/ProtoBench.java
diff options
context:
space:
mode:
Diffstat (limited to 'benchmarks/java/src/main/java/com/google/protobuf/ProtoBench.java')
-rwxr-xr-xbenchmarks/java/src/main/java/com/google/protobuf/ProtoBench.java40
1 files changed, 36 insertions, 4 deletions
diff --git a/benchmarks/java/src/main/java/com/google/protobuf/ProtoBench.java b/benchmarks/java/src/main/java/com/google/protobuf/ProtoBench.java
index abd9200e..f8d3b797 100755
--- a/benchmarks/java/src/main/java/com/google/protobuf/ProtoBench.java
+++ b/benchmarks/java/src/main/java/com/google/protobuf/ProtoBench.java
@@ -43,14 +43,18 @@ import com.google.protobuf.Message;
import com.google.protobuf.benchmarks.Benchmarks.BenchmarkDataset;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
+import java.util.Scanner;
public class ProtoBench {
@@ -71,6 +75,7 @@ public class ProtoBench {
}
System.exit(success ? 0 : 1);
}
+
/**
* Runs a single test with specific test data. Error messages are displayed to stderr,
@@ -86,7 +91,6 @@ public class ProtoBench {
System.err.println("Unable to get input data");
return false;
}
-
List<String> argsList = getCaliperOption(benchmarkDataset);
if (argsList == null) {
System.err.println("Unable to get default message " + benchmarkDataset.getMessageName());
@@ -98,15 +102,40 @@ public class ProtoBench {
try {
String args[] = new String[argsList.size()];
argsList.toArray(args);
- CaliperMain.exitlessMain(args,
+ CaliperMain.exitlessMain(args,
new PrintWriter(System.out, true), new PrintWriter(System.err, true));
- return true;
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
System.err.println("Detailed exception information:");
e.printStackTrace(System.err);
return false;
}
+ try {
+ double mininumScale = 0;
+ // If the file not exist, this will throw IOException, which won't print the warning
+ // information below.
+ Scanner scanner = new Scanner(new String(readAllBytes("JavaBenchmarkWarning.txt")));
+ while (scanner.hasNext()) {
+ mininumScale = Math.max(mininumScale, scanner.nextDouble());
+ }
+ scanner.close();
+
+ System.out.println(
+ "WARNING: This benchmark's whole iterations are not enough, consider to config caliper to "
+ + "run for more time to make the result more convincing. You may change the configure "
+ + "code in com.google.protobuf.ProtoBench.getCaliperOption() of benchmark "
+ + benchmarkDataset.getMessageName()
+ + " to run for more time. e.g. Change the value of "
+ + "instrument.runtime.options.timingInterval or value of "
+ + "instrument.runtime.options.measurements to be at least "
+ + Math.round(mininumScale * 10 + 1) / 10.0
+ + " times of before, then build and run the benchmark again\n");
+ Files.deleteIfExists(Paths.get("JavaBenchmarkWarning.txt"));
+ } catch (IOException e) {
+ // The IOException here should be file not found, which means there's no warning generated by
+ // The benchmark, so this IOException should be discarded.
+ }
+ return true;
}
@@ -121,9 +150,13 @@ public class ProtoBench {
} else if (benchmarkDataset.getMessageName().
equals("benchmarks.google_message3.GoogleMessage3")) {
temp.add("-DbenchmarkMessageType=GOOGLE_MESSAGE3");
+ temp.add("-Cinstrument.runtime.options.timingInterval=3000ms");
+ temp.add("-Cinstrument.runtime.options.measurements=20");
} else if (benchmarkDataset.getMessageName().
equals("benchmarks.google_message4.GoogleMessage4")) {
temp.add("-DbenchmarkMessageType=GOOGLE_MESSAGE4");
+ temp.add("-Cinstrument.runtime.options.timingInterval=1500ms");
+ temp.add("-Cinstrument.runtime.options.measurements=20");
} else {
return null;
}
@@ -134,7 +167,6 @@ public class ProtoBench {
String benchmarkNames = "serializeToByteString,serializeToByteArray,serializeToMemoryStream"
+ ",deserializeFromByteString,deserializeFromByteArray,deserializeFromMemoryStream";
temp.add(benchmarkNames);
- temp.add("-Cinstrument.runtime.options.timingInterval=3000ms");
return temp;
}