diff options
author | Yilun Chong <yilunchong@google.com> | 2018-01-05 16:28:51 -0800 |
---|---|---|
committer | Yilun Chong <yilunchong@google.com> | 2018-01-05 16:28:51 -0800 |
commit | 195253c3f6e698fba8b58d7c810610dd86855d14 (patch) | |
tree | f627c422b454d2a15e702f1cbc7fbaaf3b75ca63 /benchmarks/java/src/main/java/com/google/protobuf/ProtoBench.java | |
parent | 43caa38d6ed68129d28bf4528488e4f389a33b34 (diff) | |
download | protobuf-195253c3f6e698fba8b58d7c810610dd86855d14.tar.gz protobuf-195253c3f6e698fba8b58d7c810610dd86855d14.tar.bz2 protobuf-195253c3f6e698fba8b58d7c810610dd86855d14.zip |
Add counter to Java benchmark
Diffstat (limited to 'benchmarks/java/src/main/java/com/google/protobuf/ProtoBench.java')
-rwxr-xr-x | benchmarks/java/src/main/java/com/google/protobuf/ProtoBench.java | 40 |
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; } |