]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/java/test/org/apache/thrift/protocol/BenchmarkProtocols.java
1 package org
.apache
.thrift
.protocol
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Collections
;
5 import java
.util
.HashMap
;
6 import java
.util
.LinkedHashSet
;
11 import org
.apache
.thrift
.Fixtures
;
12 import org
.apache
.thrift
.TException
;
13 import org
.apache
.thrift
.transport
.TMemoryBuffer
;
15 public class BenchmarkProtocols
{
17 private static final Set
<TProtocolFactory
> FACTORIES
= new LinkedHashSet
<TProtocolFactory
>(){{
18 add(new TTupleProtocol
.Factory());
19 add(new TCompactProtocol
.Factory());
20 add(new TBinaryProtocol
.Factory());
23 private static final int NUM_REPS
= 100000;
24 private static final int NUM_TRIALS
= 10;
26 public static void main(String
[] args
) throws TException
{
27 Map
<TProtocolFactory
, List
<Long
>> timesByFactory
= new HashMap
<TProtocolFactory
, List
<Long
>>();
29 for (int trial
= 0; trial
< NUM_TRIALS
; trial
++) {
30 for (int i
= 0; i
< 16; i
++) {
33 // TProtocol proto = factory.getProtocol(new TTransport() {
35 // public void write(byte[] buf, int off, int len) throws TTransportException {
39 // public int read(byte[] buf, int off, int len) throws TTransportException {
44 // public void open() throws TTransportException {
48 // public boolean isOpen() {
53 // public void close() {
58 for (TProtocolFactory factory
: FACTORIES
) {
59 if (timesByFactory
.get(factory
) == null) {
60 timesByFactory
.put(factory
, new ArrayList
<Long
>());
63 long start
= System
.currentTimeMillis();
64 for (int rep
= 0; rep
< NUM_REPS
; rep
++) {
65 TProtocol proto
= factory
.getProtocol(new TMemoryBuffer(128*1024));
66 Fixtures
.compactProtoTestStruct
.write(proto
);
67 Fixtures
.nesting
.write(proto
);
69 long end
= System
.currentTimeMillis();
70 timesByFactory
.get(factory
).add(end
-start
);
74 for (TProtocolFactory factory
: FACTORIES
) {
75 List
<Long
> times
= timesByFactory
.get(factory
);
76 // System.out.println("raw times pre-drop: " + times );
77 times
.remove(Collections
.max(times
));
79 for (long t
: times
) {
82 Collections
.sort(times
);
83 System
.out
.println(factory
.getClass().getName() + " average time: " + (total
/ times
.size()) + "ms");
84 System
.out
.println("raw times: " + times
);