Add dependencies locally
This commit is contained in:
98
deps/protobuf/benchmarks/java/pom.xml
vendored
Normal file
98
deps/protobuf/benchmarks/java/pom.xml
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>protobuf-java-benchmark</artifactId>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<version>1.0.0</version>
|
||||
<name>Protocol Buffers [Benchmark]</name>
|
||||
<description>The benchmark tools for Protobuf Java.</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
<version>${protobuf.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/protobuf-java.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.caliper</groupId>
|
||||
<artifactId>caliper</artifactId>
|
||||
<version>1.0-beta-3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.4.1</version>
|
||||
<configuration>
|
||||
<!-- get all project dependencies -->
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<!-- MainClass in mainfest make a executable jar -->
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>com.mkyong.core.utils.App</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<!-- bind to the packaging phase -->
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<mainClass>com.google.protocolbuffers.ProtoBench</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
||||
|
208
deps/protobuf/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java
vendored
Normal file
208
deps/protobuf/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java
vendored
Normal file
@ -0,0 +1,208 @@
|
||||
package com.google.protobuf;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Benchmark;
|
||||
import com.google.caliper.Param;
|
||||
import com.google.protobuf.benchmarks.Benchmarks.BenchmarkDataset;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Basic benchmarks for Java protobuf parsing.
|
||||
*/
|
||||
public class ProtoCaliperBenchmark {
|
||||
public enum BenchmarkMessageType {
|
||||
GOOGLE_MESSAGE1_PROTO3 {
|
||||
@Override
|
||||
ExtensionRegistry getExtensionRegistry() {
|
||||
return ExtensionRegistry.newInstance();
|
||||
}
|
||||
@Override
|
||||
Message getDefaultInstance() {
|
||||
return com.google.protobuf.benchmarks.BenchmarkMessage1Proto3.GoogleMessage1
|
||||
.getDefaultInstance();
|
||||
}
|
||||
},
|
||||
GOOGLE_MESSAGE1_PROTO2 {
|
||||
@Override ExtensionRegistry getExtensionRegistry() {
|
||||
return ExtensionRegistry.newInstance();
|
||||
}
|
||||
@Override
|
||||
Message getDefaultInstance() {
|
||||
return com.google.protobuf.benchmarks.BenchmarkMessage1Proto2.GoogleMessage1
|
||||
.getDefaultInstance();
|
||||
}
|
||||
},
|
||||
GOOGLE_MESSAGE2 {
|
||||
@Override
|
||||
ExtensionRegistry getExtensionRegistry() {
|
||||
return ExtensionRegistry.newInstance();
|
||||
}
|
||||
@Override
|
||||
Message getDefaultInstance() {
|
||||
return com.google.protobuf.benchmarks.BenchmarkMessage2.GoogleMessage2.getDefaultInstance();
|
||||
}
|
||||
},
|
||||
GOOGLE_MESSAGE3 {
|
||||
@Override
|
||||
ExtensionRegistry getExtensionRegistry() {
|
||||
ExtensionRegistry extensions = ExtensionRegistry.newInstance();
|
||||
com.google.protobuf.benchmarks.BenchmarkMessage38.registerAllExtensions(extensions);
|
||||
com.google.protobuf.benchmarks.BenchmarkMessage37.registerAllExtensions(extensions);
|
||||
com.google.protobuf.benchmarks.BenchmarkMessage36.registerAllExtensions(extensions);
|
||||
com.google.protobuf.benchmarks.BenchmarkMessage35.registerAllExtensions(extensions);
|
||||
com.google.protobuf.benchmarks.BenchmarkMessage34.registerAllExtensions(extensions);
|
||||
com.google.protobuf.benchmarks.BenchmarkMessage33.registerAllExtensions(extensions);
|
||||
com.google.protobuf.benchmarks.BenchmarkMessage32.registerAllExtensions(extensions);
|
||||
com.google.protobuf.benchmarks.BenchmarkMessage31.registerAllExtensions(extensions);
|
||||
com.google.protobuf.benchmarks.BenchmarkMessage3.registerAllExtensions(extensions);
|
||||
return extensions;
|
||||
}
|
||||
@Override
|
||||
Message getDefaultInstance() {
|
||||
return com.google.protobuf.benchmarks.BenchmarkMessage3.GoogleMessage3.getDefaultInstance();
|
||||
}
|
||||
},
|
||||
GOOGLE_MESSAGE4 {
|
||||
@Override
|
||||
ExtensionRegistry getExtensionRegistry() {
|
||||
ExtensionRegistry extensions = ExtensionRegistry.newInstance();
|
||||
com.google.protobuf.benchmarks.BenchmarkMessage43.registerAllExtensions(extensions);
|
||||
com.google.protobuf.benchmarks.BenchmarkMessage42.registerAllExtensions(extensions);
|
||||
com.google.protobuf.benchmarks.BenchmarkMessage41.registerAllExtensions(extensions);
|
||||
com.google.protobuf.benchmarks.BenchmarkMessage4.registerAllExtensions(extensions);
|
||||
return extensions;
|
||||
}
|
||||
@Override
|
||||
Message getDefaultInstance() {
|
||||
return com.google.protobuf.benchmarks.BenchmarkMessage4.GoogleMessage4.getDefaultInstance();
|
||||
}
|
||||
};
|
||||
|
||||
abstract ExtensionRegistry getExtensionRegistry();
|
||||
abstract Message getDefaultInstance();
|
||||
}
|
||||
|
||||
private BenchmarkMessageType benchmarkMessageType;
|
||||
@Param("")
|
||||
private String dataFile;
|
||||
|
||||
private byte[] inputData;
|
||||
private BenchmarkDataset benchmarkDataset;
|
||||
private Message defaultMessage;
|
||||
private ExtensionRegistry extensions;
|
||||
private List<byte[]> inputDataList;
|
||||
private List<ByteArrayInputStream> inputStreamList;
|
||||
private List<ByteString> inputStringList;
|
||||
private List<Message> sampleMessageList;
|
||||
|
||||
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
|
||||
void setUp() throws IOException {
|
||||
if (!dataFile.equals("")) {
|
||||
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();
|
||||
extensions = benchmarkMessageType.getExtensionRegistry();
|
||||
inputDataList = new ArrayList<byte[]>();
|
||||
inputStreamList = new ArrayList<ByteArrayInputStream>();
|
||||
inputStringList = new ArrayList<ByteString>();
|
||||
sampleMessageList = new ArrayList<Message>();
|
||||
|
||||
for (int i = 0; i < benchmarkDataset.getPayloadCount(); i++) {
|
||||
byte[] singleInputData = benchmarkDataset.getPayload(i).toByteArray();
|
||||
inputDataList.add(benchmarkDataset.getPayload(i).toByteArray());
|
||||
inputStreamList.add(new ByteArrayInputStream(
|
||||
benchmarkDataset.getPayload(i).toByteArray()));
|
||||
inputStringList.add(benchmarkDataset.getPayload(i));
|
||||
sampleMessageList.add(
|
||||
defaultMessage.newBuilderForType().mergeFrom(singleInputData, extensions).build());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Benchmark
|
||||
void serializeToByteArray(int reps) throws IOException {
|
||||
if (sampleMessageList.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < reps; i++) {
|
||||
for (int j = 0; j < sampleMessageList.size(); j++) {
|
||||
sampleMessageList.get(j).toByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
void serializeToMemoryStream(int reps) throws IOException {
|
||||
if (sampleMessageList.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < reps; i++) {
|
||||
for (int j = 0; j < sampleMessageList.size(); j++) {
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
sampleMessageList.get(j).writeTo(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
void deserializeFromByteArray(int reps) throws IOException {
|
||||
if (inputDataList.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < reps; i++) {
|
||||
for (int j = 0; j < inputDataList.size(); j++) {
|
||||
benchmarkMessageType.getDefaultInstance().getParserForType().parseFrom(
|
||||
inputDataList.get(j), extensions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
void deserializeFromMemoryStream(int reps) throws IOException {
|
||||
if (inputStreamList.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < reps; i++) {
|
||||
for (int j = 0; j < inputStreamList.size(); j++) {
|
||||
benchmarkMessageType.getDefaultInstance().getParserForType().parseFrom(
|
||||
inputStreamList.get(j), extensions);
|
||||
inputStreamList.get(j).reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user