Merge pull request #4302 from BSBandme/down_integ_benchmark

Sync internal benchmark changes
pull/4300/merge
Yilun Chong 7 years ago committed by GitHub
commit 96b535cc2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      benchmarks/Makefile.am
  2. 2
      benchmarks/cpp_benchmark.cc
  3. 1
      benchmarks/datasets/google_message3/benchmark_message3.proto
  4. 1
      benchmarks/datasets/google_message3/benchmark_message3_1.proto
  5. 1
      benchmarks/datasets/google_message3/benchmark_message3_2.proto
  6. 1
      benchmarks/datasets/google_message3/benchmark_message3_3.proto
  7. 1
      benchmarks/datasets/google_message3/benchmark_message3_4.proto
  8. 1
      benchmarks/datasets/google_message3/benchmark_message3_5.proto
  9. 1
      benchmarks/datasets/google_message3/benchmark_message3_6.proto
  10. 1
      benchmarks/datasets/google_message3/benchmark_message3_7.proto
  11. 1
      benchmarks/datasets/google_message3/benchmark_message3_8.proto
  12. 1
      benchmarks/datasets/google_message4/benchmark_message4.proto
  13. 1
      benchmarks/datasets/google_message4/benchmark_message4_1.proto
  14. 1
      benchmarks/datasets/google_message4/benchmark_message4_2.proto
  15. 1
      benchmarks/datasets/google_message4/benchmark_message4_3.proto
  16. 10
      benchmarks/java/src/main/java/com/google/protobuf/ProtoBench.java
  17. 90
      benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java

@ -104,7 +104,7 @@ initialize_submodule:
oldpwd=`pwd` oldpwd=`pwd`
cd $(top_srcdir)/third_party cd $(top_srcdir)/third_party
git submodule update --init -r git submodule update --init -r
cd $(top_srcdir)/third_party/benchmark && cmake -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_ENABLE_GTEST_TESTS=OFF && make cd $(top_srcdir)/third_party/benchmark && cmake -DCMAKE_BUILD_TYPE=Release && make
cd $$oldpwd cd $$oldpwd
touch initialize_submodule touch initialize_submodule
@ -137,7 +137,7 @@ cpp: protoc_middleman protoc_middleman2 cpp-benchmark initialize_submodule
java_benchmark_testing_files = \ java_benchmark_testing_files = \
java/src/main/java/com/google/protobuf/ProtoBench.java \ java/src/main/java/com/google/protobuf/ProtoBench.java \
java/src/main/java/com/google/protobuf/ProtoBenchCaliper.java java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java
javac_middleman: $(java_benchmark_testing_files) protoc_middleman protoc_middleman2 javac_middleman: $(java_benchmark_testing_files) protoc_middleman protoc_middleman2
cp -r java tmp && cd tmp/java && mvn clean compile assembly:single cp -r java tmp && cd tmp/java && mvn clean compile assembly:single

@ -238,6 +238,7 @@ void RegisterBenchmarks(const std::string& dataset_bytes) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
::benchmark::Initialize(&argc, argv);
if (argc == 1) { if (argc == 1) {
std::cerr << "Usage: ./cpp-benchmark <input data>" << std::endl; std::cerr << "Usage: ./cpp-benchmark <input data>" << std::endl;
std::cerr << "input data is in the format of \"benchmarks.proto\"" std::cerr << "input data is in the format of \"benchmarks.proto\""
@ -249,6 +250,5 @@ int main(int argc, char *argv[]) {
} }
} }
::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks(); ::benchmark::RunSpecifiedBenchmarks();
} }

@ -10,6 +10,7 @@ import "datasets/google_message3/benchmark_message3_8.proto";
package benchmarks.google_message3; package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks";
message GoogleMessage3 { message GoogleMessage3 {
optional .benchmarks.google_message3.Message37487 field37519 = 2; optional .benchmarks.google_message3.Message37487 field37519 = 2;

@ -8,6 +8,7 @@ import "datasets/google_message3/benchmark_message3_8.proto";
package benchmarks.google_message3; package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks";
message Message34390 { message Message34390 {
repeated .benchmarks.google_message3.Message34387 field34452 = 1; repeated .benchmarks.google_message3.Message34387 field34452 = 1;

@ -8,6 +8,7 @@ import "datasets/google_message3/benchmark_message3_8.proto";
package benchmarks.google_message3; package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks";
message Message22853 { message Message22853 {
optional .benchmarks.google_message3.Enum22854 field22869 = 1; optional .benchmarks.google_message3.Enum22854 field22869 = 1;

@ -7,6 +7,7 @@ import "datasets/google_message3/benchmark_message3_8.proto";
package benchmarks.google_message3; package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks";
message Message35546 { message Message35546 {
optional int64 field35556 = 1; optional int64 field35556 = 1;

@ -7,6 +7,7 @@ import "datasets/google_message3/benchmark_message3_8.proto";
package benchmarks.google_message3; package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks";
message Message24346 { message Message24346 {
} }

@ -6,6 +6,7 @@ import "datasets/google_message3/benchmark_message3_8.proto";
package benchmarks.google_message3; package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks";
message Message24377 { message Message24377 {
} }

@ -5,6 +5,7 @@ import "datasets/google_message3/benchmark_message3_8.proto";
package benchmarks.google_message3; package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks";
message Message10576 { message Message10576 {
} }

@ -3,6 +3,7 @@ syntax = "proto2";
package benchmarks.google_message3; package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks";
message Message11018 { message Message11018 {
} }

@ -3,6 +3,7 @@ syntax = "proto2";
package benchmarks.google_message3; package benchmarks.google_message3;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks";
enum Enum720 { enum Enum720 {
ENUM_VALUE721 = 1; ENUM_VALUE721 = 1;

@ -6,6 +6,7 @@ import "datasets/google_message4/benchmark_message4_3.proto";
package benchmarks.google_message4; package benchmarks.google_message4;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks";
message GoogleMessage4 { message GoogleMessage4 {
optional int32 field37503 = 1; optional int32 field37503 = 1;

@ -5,6 +5,7 @@ import "datasets/google_message4/benchmark_message4_3.proto";
package benchmarks.google_message4; package benchmarks.google_message4;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks";
message Message2463 { message Message2463 {
repeated .benchmarks.google_message4.Message2462 field2498 = 1; repeated .benchmarks.google_message4.Message2462 field2498 = 1;

@ -4,6 +4,7 @@ import "datasets/google_message4/benchmark_message4_3.proto";
package benchmarks.google_message4; package benchmarks.google_message4;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks";
message Message12774 { message Message12774 {
optional uint32 field12777 = 1; optional uint32 field12777 = 1;

@ -3,6 +3,7 @@ syntax = "proto2";
package benchmarks.google_message4; package benchmarks.google_message4;
option cc_enable_arenas = true; option cc_enable_arenas = true;
option java_package = "com.google.protobuf.benchmarks";
enum UnusedEnum { enum UnusedEnum {
UNUSED_ENUM_VALUE1 = 0; UNUSED_ENUM_VALUE1 = 0;

@ -97,7 +97,7 @@ public class ProtoBench {
return false; return false;
} }
argsList.add("-DdataFile=" + file); argsList.add("-DdataFile=" + file);
argsList.add("com.google.protobuf.ProtoBenchCaliper"); argsList.add("com.google.protobuf.ProtoCaliperBenchmark");
try { try {
String args[] = new String[argsList.size()]; String args[] = new String[argsList.size()];
@ -142,19 +142,14 @@ public class ProtoBench {
private static List<String> getCaliperOption(final BenchmarkDataset benchmarkDataset) { private static List<String> getCaliperOption(final BenchmarkDataset benchmarkDataset) {
List<String> temp = new ArrayList<String>(); List<String> temp = new ArrayList<String>();
if (benchmarkDataset.getMessageName().equals("benchmarks.proto3.GoogleMessage1")) { if (benchmarkDataset.getMessageName().equals("benchmarks.proto3.GoogleMessage1")) {
temp.add("-DbenchmarkMessageType=GOOGLE_MESSAGE1_PROTO3");
} else if (benchmarkDataset.getMessageName().equals("benchmarks.proto2.GoogleMessage1")) { } else if (benchmarkDataset.getMessageName().equals("benchmarks.proto2.GoogleMessage1")) {
temp.add("-DbenchmarkMessageType=GOOGLE_MESSAGE1_PROTO2");
} else if (benchmarkDataset.getMessageName().equals("benchmarks.proto2.GoogleMessage2")) { } else if (benchmarkDataset.getMessageName().equals("benchmarks.proto2.GoogleMessage2")) {
temp.add("-DbenchmarkMessageType=GOOGLE_MESSAGE2");
} else if (benchmarkDataset.getMessageName(). } else if (benchmarkDataset.getMessageName().
equals("benchmarks.google_message3.GoogleMessage3")) { equals("benchmarks.google_message3.GoogleMessage3")) {
temp.add("-DbenchmarkMessageType=GOOGLE_MESSAGE3");
temp.add("-Cinstrument.runtime.options.timingInterval=3000ms"); temp.add("-Cinstrument.runtime.options.timingInterval=3000ms");
temp.add("-Cinstrument.runtime.options.measurements=20"); temp.add("-Cinstrument.runtime.options.measurements=20");
} else if (benchmarkDataset.getMessageName(). } else if (benchmarkDataset.getMessageName().
equals("benchmarks.google_message4.GoogleMessage4")) { equals("benchmarks.google_message4.GoogleMessage4")) {
temp.add("-DbenchmarkMessageType=GOOGLE_MESSAGE4");
temp.add("-Cinstrument.runtime.options.timingInterval=1500ms"); temp.add("-Cinstrument.runtime.options.timingInterval=1500ms");
temp.add("-Cinstrument.runtime.options.measurements=20"); temp.add("-Cinstrument.runtime.options.measurements=20");
} else { } else {
@ -172,6 +167,9 @@ public class ProtoBench {
} }
public static byte[] readAllBytes(String filename) throws IOException { public static byte[] readAllBytes(String filename) throws IOException {
if (filename.equals("")) {
return new byte[0];
}
RandomAccessFile file = new RandomAccessFile(new File(filename), "r"); RandomAccessFile file = new RandomAccessFile(new File(filename), "r");
byte[] content = new byte[(int) file.length()]; byte[] content = new byte[(int) file.length()];
file.readFully(content); file.readFully(content);

@ -13,14 +13,16 @@ import com.google.protobuf.benchmarks.Benchmarks.BenchmarkDataset;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ProtoBenchCaliper { public class ProtoCaliperBenchmark {
public enum BenchmarkMessageType { public enum BenchmarkMessageType {
GOOGLE_MESSAGE1_PROTO3 { GOOGLE_MESSAGE1_PROTO3 {
@Override ExtensionRegistry getExtensionRegistry() { return ExtensionRegistry.newInstance(); } @Override ExtensionRegistry getExtensionRegistry() { return ExtensionRegistry.newInstance(); }
@ -49,45 +51,44 @@ public class ProtoBenchCaliper {
@Override @Override
ExtensionRegistry getExtensionRegistry() { ExtensionRegistry getExtensionRegistry() {
ExtensionRegistry extensions = ExtensionRegistry.newInstance(); ExtensionRegistry extensions = ExtensionRegistry.newInstance();
benchmarks.google_message3.BenchmarkMessage38.registerAllExtensions(extensions); com.google.protobuf.benchmarks.BenchmarkMessage38.registerAllExtensions(extensions);
benchmarks.google_message3.BenchmarkMessage37.registerAllExtensions(extensions); com.google.protobuf.benchmarks.BenchmarkMessage37.registerAllExtensions(extensions);
benchmarks.google_message3.BenchmarkMessage36.registerAllExtensions(extensions); com.google.protobuf.benchmarks.BenchmarkMessage36.registerAllExtensions(extensions);
benchmarks.google_message3.BenchmarkMessage35.registerAllExtensions(extensions); com.google.protobuf.benchmarks.BenchmarkMessage35.registerAllExtensions(extensions);
benchmarks.google_message3.BenchmarkMessage34.registerAllExtensions(extensions); com.google.protobuf.benchmarks.BenchmarkMessage34.registerAllExtensions(extensions);
benchmarks.google_message3.BenchmarkMessage33.registerAllExtensions(extensions); com.google.protobuf.benchmarks.BenchmarkMessage33.registerAllExtensions(extensions);
benchmarks.google_message3.BenchmarkMessage32.registerAllExtensions(extensions); com.google.protobuf.benchmarks.BenchmarkMessage32.registerAllExtensions(extensions);
benchmarks.google_message3.BenchmarkMessage31.registerAllExtensions(extensions); com.google.protobuf.benchmarks.BenchmarkMessage31.registerAllExtensions(extensions);
benchmarks.google_message3.BenchmarkMessage3.registerAllExtensions(extensions); com.google.protobuf.benchmarks.BenchmarkMessage3.registerAllExtensions(extensions);
return extensions; return extensions;
} }
@Override @Override
Message getDefaultInstance() { Message getDefaultInstance() {
return benchmarks.google_message3.BenchmarkMessage3.GoogleMessage3.getDefaultInstance(); return com.google.protobuf.benchmarks.BenchmarkMessage3.GoogleMessage3.getDefaultInstance();
} }
}, },
GOOGLE_MESSAGE4 { GOOGLE_MESSAGE4 {
@Override @Override
ExtensionRegistry getExtensionRegistry() { ExtensionRegistry getExtensionRegistry() {
ExtensionRegistry extensions = ExtensionRegistry.newInstance(); ExtensionRegistry extensions = ExtensionRegistry.newInstance();
benchmarks.google_message4.BenchmarkMessage43.registerAllExtensions(extensions); com.google.protobuf.benchmarks.BenchmarkMessage43.registerAllExtensions(extensions);
benchmarks.google_message4.BenchmarkMessage42.registerAllExtensions(extensions); com.google.protobuf.benchmarks.BenchmarkMessage42.registerAllExtensions(extensions);
benchmarks.google_message4.BenchmarkMessage41.registerAllExtensions(extensions); com.google.protobuf.benchmarks.BenchmarkMessage41.registerAllExtensions(extensions);
benchmarks.google_message4.BenchmarkMessage4.registerAllExtensions(extensions); com.google.protobuf.benchmarks.BenchmarkMessage4.registerAllExtensions(extensions);
return extensions; return extensions;
} }
@Override @Override
Message getDefaultInstance() { Message getDefaultInstance() {
return benchmarks.google_message4.BenchmarkMessage4.GoogleMessage4.getDefaultInstance(); return com.google.protobuf.benchmarks.BenchmarkMessage4.GoogleMessage4.getDefaultInstance();
} }
}; };
abstract ExtensionRegistry getExtensionRegistry(); abstract ExtensionRegistry getExtensionRegistry();
abstract Message getDefaultInstance(); abstract Message getDefaultInstance();
} }
@Param
private BenchmarkMessageType benchmarkMessageType; private BenchmarkMessageType benchmarkMessageType;
@Param @Param("")
private String dataFile; private String dataFile;
private byte[] inputData; private byte[] inputData;
@ -99,11 +100,39 @@ public class ProtoBenchCaliper {
private List<ByteString> inputStringList; private List<ByteString> inputStringList;
private List<Message> sampleMessageList; private List<Message> sampleMessageList;
private long counter; private long counter;
private BenchmarkMessageType getMessageType() throws IOException {
if (benchmarkDataset.getMessageName().equals("benchmarks.proto3.GoogleMessage1")) {
return BenchmarkMessageType.GOOGLE_MESSAGE1_PROTO3;
} else if (benchmarkDataset.getMessageName().equals("benchmarks.proto2.GoogleMessage1")) {
return BenchmarkMessageType.GOOGLE_MESSAGE1_PROTO2;
} else if (benchmarkDataset.getMessageName().equals("benchmarks.proto2.GoogleMessage2")) {
return BenchmarkMessageType.GOOGLE_MESSAGE2;
} else if (benchmarkDataset.getMessageName().
equals("benchmarks.google_message3.GoogleMessage3")) {
return BenchmarkMessageType.GOOGLE_MESSAGE3;
} else if (benchmarkDataset.getMessageName().
equals("benchmarks.google_message4.GoogleMessage4")) {
return BenchmarkMessageType.GOOGLE_MESSAGE4;
} else {
throw new IllegalStateException("Invalid DataFile! There's no testing message named "
+ benchmarkDataset.getMessageName());
}
}
@BeforeExperiment @BeforeExperiment
void setUp() throws IOException { void setUp() throws IOException {
inputData = ProtoBench.readAllBytes(dataFile); if (!dataFile.equals("")) {
benchmarkDataset = BenchmarkDataset.parseFrom(inputData); RandomAccessFile file = new RandomAccessFile(new File(dataFile), "r");
inputData = new byte[(int) file.length()];
file.readFully(inputData);
benchmarkDataset = BenchmarkDataset.parseFrom(inputData);
benchmarkMessageType = getMessageType();
} else {
inputData = new byte[0];
benchmarkDataset = BenchmarkDataset.parseFrom(inputData);
benchmarkMessageType = BenchmarkMessageType.GOOGLE_MESSAGE2;
}
defaultMessage = benchmarkMessageType.getDefaultInstance(); defaultMessage = benchmarkMessageType.getDefaultInstance();
extensions = benchmarkMessageType.getExtensionRegistry(); extensions = benchmarkMessageType.getExtensionRegistry();
inputDataList = new ArrayList<byte[]>(); inputDataList = new ArrayList<byte[]>();
@ -127,6 +156,9 @@ public class ProtoBenchCaliper {
@Benchmark @Benchmark
void serializeToByteString(int reps) throws IOException { void serializeToByteString(int reps) throws IOException {
if (sampleMessageList.size() == 0) {
return;
}
for (int i = 0; i < reps; i++) { for (int i = 0; i < reps; i++) {
sampleMessageList.get((int) (counter % sampleMessageList.size())).toByteString(); sampleMessageList.get((int) (counter % sampleMessageList.size())).toByteString();
counter++; counter++;
@ -135,6 +167,9 @@ public class ProtoBenchCaliper {
@Benchmark @Benchmark
void serializeToByteArray(int reps) throws IOException { void serializeToByteArray(int reps) throws IOException {
if (sampleMessageList.size() == 0) {
return;
}
for (int i = 0; i < reps; i++) { for (int i = 0; i < reps; i++) {
sampleMessageList.get((int) (counter % sampleMessageList.size())).toByteArray(); sampleMessageList.get((int) (counter % sampleMessageList.size())).toByteArray();
counter++; counter++;
@ -143,6 +178,9 @@ public class ProtoBenchCaliper {
@Benchmark @Benchmark
void serializeToMemoryStream(int reps) throws IOException { void serializeToMemoryStream(int reps) throws IOException {
if (sampleMessageList.size() == 0) {
return;
}
for (int i = 0; i < reps; i++) { for (int i = 0; i < reps; i++) {
ByteArrayOutputStream output = new ByteArrayOutputStream(); ByteArrayOutputStream output = new ByteArrayOutputStream();
sampleMessageList.get((int) (counter % sampleMessageList.size())).writeTo(output); sampleMessageList.get((int) (counter % sampleMessageList.size())).writeTo(output);
@ -152,6 +190,9 @@ public class ProtoBenchCaliper {
@Benchmark @Benchmark
void deserializeFromByteString(int reps) throws IOException { void deserializeFromByteString(int reps) throws IOException {
if (inputStringList.size() == 0) {
return;
}
for (int i = 0; i < reps; i++) { for (int i = 0; i < reps; i++) {
benchmarkMessageType.getDefaultInstance().getParserForType().parseFrom( benchmarkMessageType.getDefaultInstance().getParserForType().parseFrom(
inputStringList.get((int) (counter % inputStringList.size())), extensions); inputStringList.get((int) (counter % inputStringList.size())), extensions);
@ -161,6 +202,9 @@ public class ProtoBenchCaliper {
@Benchmark @Benchmark
void deserializeFromByteArray(int reps) throws IOException { void deserializeFromByteArray(int reps) throws IOException {
if (inputDataList.size() == 0) {
return;
}
for (int i = 0; i < reps; i++) { for (int i = 0; i < reps; i++) {
benchmarkMessageType.getDefaultInstance().getParserForType().parseFrom( benchmarkMessageType.getDefaultInstance().getParserForType().parseFrom(
inputDataList.get((int) (counter % inputDataList.size())), extensions); inputDataList.get((int) (counter % inputDataList.size())), extensions);
@ -170,6 +214,9 @@ public class ProtoBenchCaliper {
@Benchmark @Benchmark
void deserializeFromMemoryStream(int reps) throws IOException { void deserializeFromMemoryStream(int reps) throws IOException {
if (inputStreamList.size() == 0) {
return;
}
for (int i = 0; i < reps; i++) { for (int i = 0; i < reps; i++) {
benchmarkMessageType.getDefaultInstance().getParserForType().parseFrom( benchmarkMessageType.getDefaultInstance().getParserForType().parseFrom(
inputStreamList.get((int) (counter % inputStreamList.size())), extensions); inputStreamList.get((int) (counter % inputStreamList.size())), extensions);
@ -195,3 +242,4 @@ public class ProtoBenchCaliper {
} }
} }
} }
Loading…
Cancel
Save