Skip to content

Commit

Permalink
QuickBuffers 1.4 (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
ennerf committed Mar 2, 2024
1 parent 2856c61 commit 73c77af
Show file tree
Hide file tree
Showing 13 changed files with 6,475 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ dependencies {
implementation group: 'com.github.javadev', name: 'underscore', version: '1.97'
// yasson
implementation group: 'org.eclipse', name: 'yasson', version: '3.0.3'
// QuickBuffers
implementation group: 'us.hebi.quickbuf', name: 'quickbuf-runtime', version: '1.4'

// Test
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/github/fabienrenaud/jjb/JsonBench.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,9 @@ public Object qson() throws Exception {
public Object antons() throws Exception {
return null;
}

public Object quickbuf_json() throws Exception {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import okio.BufferedSource;
import okio.ForwardingSource;
import okio.Okio;
import us.hebi.quickbuf.ProtoMessage;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand All @@ -21,6 +22,7 @@ public abstract class JsonSource<T> {
private final T[] jsonAsObject;
private final String[] jsonAsString;
private final byte[][] jsonAsBytes;
private final ProtoMessage<?>[] jsonAsQuickbufObject;
private final ThreadLocal<ByteArrayInputStream[]> jsonAsByteArrayInputStream;

private final DataGenerator<T> dataGenerator;
Expand All @@ -33,6 +35,7 @@ public abstract class JsonSource<T> {
this.jsonAsObject = newPojoArray(quantity);
this.jsonAsString = new String[quantity];
this.jsonAsBytes = new byte[quantity][];
this.jsonAsQuickbufObject = new ProtoMessage<?>[quantity];

this.dataGenerator = dataGenerator;
this.streamSerializer = streamSerializer;
Expand All @@ -58,6 +61,8 @@ private void populateFields(int quantity, int individualSize) {
String json = provider.jackson().writeValueAsString(obj);
jsonAsString[i] = json;
jsonAsBytes[i] = json.getBytes();
jsonAsQuickbufObject[i] = provider().quickbufPojo().clearQuick().clone().mergeFrom(
us.hebi.quickbuf.JsonSource.newInstance(jsonAsBytes[i]).setIgnoreUnknownFields(false));
}
} catch (Exception ex) {
ex.printStackTrace();
Expand Down Expand Up @@ -100,6 +105,10 @@ public T nextPojo() {
return jsonAsObject[index(jsonAsObject.length)];
}

public ProtoMessage<?> nextQuickbufPojo() {
return jsonAsQuickbufObject[index(jsonAsQuickbufObject.length)];
}

public StreamSerializer<T> streamSerializer() {
return streamSerializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,12 @@ public Object moshi() throws Exception {
public Object qson() throws Exception {
return JSON_SOURCE().provider().qson().read(JSON_SOURCE().nextByteArray(), JSON_SOURCE().pojoType());
}

@Benchmark
@Override
public Object quickbuf_json() throws Exception {
return JSON_SOURCE().provider().quickbufPojo().clearQuick()
.mergeFrom(us.hebi.quickbuf.JsonSource.newInstance(JSON_SOURCE().nextByteArray()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,11 @@ public Object qson() throws Exception {
JSON_SOURCE().provider().qson().writeStream(JSON_SOURCE().nextPojo(), baos);
return baos;
}

@Benchmark
@Override
public Object quickbuf_json() throws Exception {
return JSON_SOURCE().provider().quickbufSink().clear().writeMessage(JSON_SOURCE().nextQuickbufPojo());
}

}
Loading

0 comments on commit 73c77af

Please sign in to comment.