Skip to content

Commit

Permalink
fix: upgraded jmh usage of protobuf deps (#294)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Peterson <matt.peterson@swirldslabs.com>
  • Loading branch information
mattp-swirldslabs authored Sep 30, 2024
1 parent 5246bcb commit 8c8dba9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hedera.pbj.intergration.jmh;

import com.google.protobuf.GeneratedMessage;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
Expand All @@ -13,7 +14,16 @@
import com.hedera.pbj.runtime.io.buffer.BufferedData;
import com.hedera.pbj.test.proto.pbj.Everything;
import com.hederahashgraph.api.proto.java.GetAccountDetailsResponse;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

import java.io.IOException;
Expand All @@ -26,13 +36,13 @@
@Measurement(iterations = 5, time = 2)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
public abstract class JsonBench<P extends Record,G extends GeneratedMessageV3> {
public abstract class JsonBench<P extends Record,G extends GeneratedMessage> {

@SuppressWarnings("rawtypes")
@State(Scope.Benchmark)
public static class JsonBenchmarkState<P extends Record,G extends GeneratedMessageV3> {
public static class JsonBenchmarkState<P extends Record,G extends GeneratedMessage> {
private JsonCodec<P> pbjJsonCodec;
private Supplier<GeneratedMessageV3.Builder> builderSupplier;
private Supplier<GeneratedMessage.Builder> builderSupplier;
// input objects
private P pbjModelObject;
private G googleModelObject;
Expand All @@ -45,7 +55,7 @@ public static class JsonBenchmarkState<P extends Record,G extends GeneratedMessa
private BufferedData outDataBuffer;
public void configure(P pbjModelObject, Codec<P> pbjProtoCodec, JsonCodec<P> pbjJsonCodec,
ProtobufObjectBench.ProtobufParseFunction<byte[],G> googleByteArrayParseMethod,
Supplier<GeneratedMessageV3.Builder> builderSupplier) {
Supplier<GeneratedMessage.Builder> builderSupplier) {
try {
this.pbjModelObject = pbjModelObject;
this.pbjJsonCodec = pbjJsonCodec;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hedera.pbj.intergration.jmh;

import com.google.protobuf.CodedOutputStream;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.GeneratedMessage;
import com.hedera.hapi.node.base.Timestamp;
import com.hedera.hapi.node.token.AccountDetails;
import com.hedera.pbj.integration.AccountDetailsPbj;
Expand All @@ -15,7 +15,17 @@
import com.hedera.pbj.runtime.io.stream.WritableStreamingData;
import com.hedera.pbj.test.proto.pbj.Everything;
import com.hederahashgraph.api.proto.java.GetAccountDetailsResponse;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

import java.io.IOException;
Expand All @@ -29,12 +39,12 @@
@Measurement(iterations = 5, time = 2)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
public abstract class ProtobufObjectBench<P extends Record,G extends GeneratedMessageV3> {
public abstract class ProtobufObjectBench<P extends Record,G extends GeneratedMessage> {
/** we repeat all operations 1000 times so that measured times are nig enough */
private static final int OPERATION_COUNT = 1000;

@State(Scope.Benchmark)
public static class BenchmarkState<P extends Record,G extends GeneratedMessageV3> {
public static class BenchmarkState<P extends Record,G extends GeneratedMessage> {
private Codec<P> pbjCodec;
private ProtobufParseFunction<byte[], G> googleByteArrayParseMethod;
private ProtobufParseFunction<ByteBuffer, G> googleByteBufferParseMethod;
Expand Down

0 comments on commit 8c8dba9

Please sign in to comment.