1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20package thrift
21
22import (
23	"bytes"
24	"testing"
25)
26
27var binaryProtoF = NewTBinaryProtocolFactoryDefault()
28var compactProtoF = NewTCompactProtocolFactory()
29
30var buf = bytes.NewBuffer(make([]byte, 0, 1024))
31
32var tfv = []TTransportFactory{
33	NewTMemoryBufferTransportFactory(1024),
34	NewStreamTransportFactory(buf, buf, true),
35	NewTFramedTransportFactory(NewTMemoryBufferTransportFactory(1024)),
36}
37
38func BenchmarkBinaryBool_0(b *testing.B) {
39	trans, err := tfv[0].GetTransport(nil)
40	if err != nil {
41		b.Fatal(err)
42	}
43	p := binaryProtoF.GetProtocol(trans)
44	for i := 0; i < b.N; i++ {
45		ReadWriteBool(b, p, trans)
46	}
47}
48
49func BenchmarkBinaryByte_0(b *testing.B) {
50	trans, err := tfv[0].GetTransport(nil)
51	if err != nil {
52		b.Fatal(err)
53	}
54	p := binaryProtoF.GetProtocol(trans)
55	for i := 0; i < b.N; i++ {
56		ReadWriteByte(b, p, trans)
57	}
58}
59
60func BenchmarkBinaryI16_0(b *testing.B) {
61	trans, err := tfv[0].GetTransport(nil)
62	if err != nil {
63		b.Fatal(err)
64	}
65	p := binaryProtoF.GetProtocol(trans)
66	for i := 0; i < b.N; i++ {
67		ReadWriteI16(b, p, trans)
68	}
69}
70
71func BenchmarkBinaryI32_0(b *testing.B) {
72	trans, err := tfv[0].GetTransport(nil)
73	if err != nil {
74		b.Fatal(err)
75	}
76	p := binaryProtoF.GetProtocol(trans)
77	for i := 0; i < b.N; i++ {
78		ReadWriteI32(b, p, trans)
79	}
80}
81func BenchmarkBinaryI64_0(b *testing.B) {
82	trans, err := tfv[0].GetTransport(nil)
83	if err != nil {
84		b.Fatal(err)
85	}
86	p := binaryProtoF.GetProtocol(trans)
87	for i := 0; i < b.N; i++ {
88		ReadWriteI64(b, p, trans)
89	}
90}
91func BenchmarkBinaryDouble_0(b *testing.B) {
92	trans, err := tfv[0].GetTransport(nil)
93	if err != nil {
94		b.Fatal(err)
95	}
96	p := binaryProtoF.GetProtocol(trans)
97	for i := 0; i < b.N; i++ {
98		ReadWriteDouble(b, p, trans)
99	}
100}
101func BenchmarkBinaryString_0(b *testing.B) {
102	trans, err := tfv[0].GetTransport(nil)
103	if err != nil {
104		b.Fatal(err)
105	}
106	p := binaryProtoF.GetProtocol(trans)
107	for i := 0; i < b.N; i++ {
108		ReadWriteString(b, p, trans)
109	}
110}
111func BenchmarkBinaryBinary_0(b *testing.B) {
112	trans, err := tfv[0].GetTransport(nil)
113	if err != nil {
114		b.Fatal(err)
115	}
116	p := binaryProtoF.GetProtocol(trans)
117	for i := 0; i < b.N; i++ {
118		ReadWriteBinary(b, p, trans)
119	}
120}
121
122func BenchmarkBinaryBool_1(b *testing.B) {
123	trans, err := tfv[1].GetTransport(nil)
124	if err != nil {
125		b.Fatal(err)
126	}
127	p := binaryProtoF.GetProtocol(trans)
128	for i := 0; i < b.N; i++ {
129		ReadWriteBool(b, p, trans)
130	}
131}
132
133func BenchmarkBinaryByte_1(b *testing.B) {
134	trans, err := tfv[1].GetTransport(nil)
135	if err != nil {
136		b.Fatal(err)
137	}
138	p := binaryProtoF.GetProtocol(trans)
139	for i := 0; i < b.N; i++ {
140		ReadWriteByte(b, p, trans)
141	}
142}
143
144func BenchmarkBinaryI16_1(b *testing.B) {
145	trans, err := tfv[1].GetTransport(nil)
146	if err != nil {
147		b.Fatal(err)
148	}
149	p := binaryProtoF.GetProtocol(trans)
150	for i := 0; i < b.N; i++ {
151		ReadWriteI16(b, p, trans)
152	}
153}
154
155func BenchmarkBinaryI32_1(b *testing.B) {
156	trans, err := tfv[1].GetTransport(nil)
157	if err != nil {
158		b.Fatal(err)
159	}
160	p := binaryProtoF.GetProtocol(trans)
161	for i := 0; i < b.N; i++ {
162		ReadWriteI32(b, p, trans)
163	}
164}
165func BenchmarkBinaryI64_1(b *testing.B) {
166	trans, err := tfv[1].GetTransport(nil)
167	if err != nil {
168		b.Fatal(err)
169	}
170	p := binaryProtoF.GetProtocol(trans)
171	for i := 0; i < b.N; i++ {
172		ReadWriteI64(b, p, trans)
173	}
174}
175func BenchmarkBinaryDouble_1(b *testing.B) {
176	trans, err := tfv[1].GetTransport(nil)
177	if err != nil {
178		b.Fatal(err)
179	}
180	p := binaryProtoF.GetProtocol(trans)
181	for i := 0; i < b.N; i++ {
182		ReadWriteDouble(b, p, trans)
183	}
184}
185func BenchmarkBinaryString_1(b *testing.B) {
186	trans, err := tfv[1].GetTransport(nil)
187	if err != nil {
188		b.Fatal(err)
189	}
190	p := binaryProtoF.GetProtocol(trans)
191	for i := 0; i < b.N; i++ {
192		ReadWriteString(b, p, trans)
193	}
194}
195func BenchmarkBinaryBinary_1(b *testing.B) {
196	trans, err := tfv[1].GetTransport(nil)
197	if err != nil {
198		b.Fatal(err)
199	}
200	p := binaryProtoF.GetProtocol(trans)
201	for i := 0; i < b.N; i++ {
202		ReadWriteBinary(b, p, trans)
203	}
204}
205
206func BenchmarkBinaryBool_2(b *testing.B) {
207	trans, err := tfv[2].GetTransport(nil)
208	if err != nil {
209		b.Fatal(err)
210	}
211	p := binaryProtoF.GetProtocol(trans)
212	for i := 0; i < b.N; i++ {
213		ReadWriteBool(b, p, trans)
214	}
215}
216
217func BenchmarkBinaryByte_2(b *testing.B) {
218	trans, err := tfv[2].GetTransport(nil)
219	if err != nil {
220		b.Fatal(err)
221	}
222	p := binaryProtoF.GetProtocol(trans)
223	for i := 0; i < b.N; i++ {
224		ReadWriteByte(b, p, trans)
225	}
226}
227
228func BenchmarkBinaryI16_2(b *testing.B) {
229	trans, err := tfv[2].GetTransport(nil)
230	if err != nil {
231		b.Fatal(err)
232	}
233	p := binaryProtoF.GetProtocol(trans)
234	for i := 0; i < b.N; i++ {
235		ReadWriteI16(b, p, trans)
236	}
237}
238
239func BenchmarkBinaryI32_2(b *testing.B) {
240	trans, err := tfv[2].GetTransport(nil)
241	if err != nil {
242		b.Fatal(err)
243	}
244	p := binaryProtoF.GetProtocol(trans)
245	for i := 0; i < b.N; i++ {
246		ReadWriteI32(b, p, trans)
247	}
248}
249func BenchmarkBinaryI64_2(b *testing.B) {
250	trans, err := tfv[2].GetTransport(nil)
251	if err != nil {
252		b.Fatal(err)
253	}
254	p := binaryProtoF.GetProtocol(trans)
255	for i := 0; i < b.N; i++ {
256		ReadWriteI64(b, p, trans)
257	}
258}
259func BenchmarkBinaryDouble_2(b *testing.B) {
260	trans, err := tfv[2].GetTransport(nil)
261	if err != nil {
262		b.Fatal(err)
263	}
264	p := binaryProtoF.GetProtocol(trans)
265	for i := 0; i < b.N; i++ {
266		ReadWriteDouble(b, p, trans)
267	}
268}
269func BenchmarkBinaryString_2(b *testing.B) {
270	trans, err := tfv[2].GetTransport(nil)
271	if err != nil {
272		b.Fatal(err)
273	}
274	p := binaryProtoF.GetProtocol(trans)
275	for i := 0; i < b.N; i++ {
276		ReadWriteString(b, p, trans)
277	}
278}
279func BenchmarkBinaryBinary_2(b *testing.B) {
280	trans, err := tfv[2].GetTransport(nil)
281	if err != nil {
282		b.Fatal(err)
283	}
284	p := binaryProtoF.GetProtocol(trans)
285	for i := 0; i < b.N; i++ {
286		ReadWriteBinary(b, p, trans)
287	}
288}
289
290func BenchmarkCompactBool_0(b *testing.B) {
291	trans, err := tfv[0].GetTransport(nil)
292	if err != nil {
293		b.Fatal(err)
294	}
295	p := compactProtoF.GetProtocol(trans)
296	for i := 0; i < b.N; i++ {
297		ReadWriteBool(b, p, trans)
298	}
299}
300
301func BenchmarkCompactByte_0(b *testing.B) {
302	trans, err := tfv[0].GetTransport(nil)
303	if err != nil {
304		b.Fatal(err)
305	}
306	p := compactProtoF.GetProtocol(trans)
307	for i := 0; i < b.N; i++ {
308		ReadWriteByte(b, p, trans)
309	}
310}
311
312func BenchmarkCompactI16_0(b *testing.B) {
313	trans, err := tfv[0].GetTransport(nil)
314	if err != nil {
315		b.Fatal(err)
316	}
317	p := compactProtoF.GetProtocol(trans)
318	for i := 0; i < b.N; i++ {
319		ReadWriteI16(b, p, trans)
320	}
321}
322
323func BenchmarkCompactI32_0(b *testing.B) {
324	trans, err := tfv[0].GetTransport(nil)
325	if err != nil {
326		b.Fatal(err)
327	}
328	p := compactProtoF.GetProtocol(trans)
329	for i := 0; i < b.N; i++ {
330		ReadWriteI32(b, p, trans)
331	}
332}
333func BenchmarkCompactI64_0(b *testing.B) {
334	trans, err := tfv[0].GetTransport(nil)
335	if err != nil {
336		b.Fatal(err)
337	}
338	p := compactProtoF.GetProtocol(trans)
339	for i := 0; i < b.N; i++ {
340		ReadWriteI64(b, p, trans)
341	}
342}
343func BenchmarkCompactDouble0(b *testing.B) {
344	trans, err := tfv[0].GetTransport(nil)
345	if err != nil {
346		b.Fatal(err)
347	}
348	p := compactProtoF.GetProtocol(trans)
349	for i := 0; i < b.N; i++ {
350		ReadWriteDouble(b, p, trans)
351	}
352}
353func BenchmarkCompactString0(b *testing.B) {
354	trans, err := tfv[0].GetTransport(nil)
355	if err != nil {
356		b.Fatal(err)
357	}
358	p := compactProtoF.GetProtocol(trans)
359	for i := 0; i < b.N; i++ {
360		ReadWriteString(b, p, trans)
361	}
362}
363func BenchmarkCompactBinary0(b *testing.B) {
364	trans, err := tfv[0].GetTransport(nil)
365	if err != nil {
366		b.Fatal(err)
367	}
368	p := compactProtoF.GetProtocol(trans)
369	for i := 0; i < b.N; i++ {
370		ReadWriteBinary(b, p, trans)
371	}
372}
373
374func BenchmarkCompactBool_1(b *testing.B) {
375	trans, err := tfv[1].GetTransport(nil)
376	if err != nil {
377		b.Fatal(err)
378	}
379	p := compactProtoF.GetProtocol(trans)
380	for i := 0; i < b.N; i++ {
381		ReadWriteBool(b, p, trans)
382	}
383}
384
385func BenchmarkCompactByte_1(b *testing.B) {
386	trans, err := tfv[1].GetTransport(nil)
387	if err != nil {
388		b.Fatal(err)
389	}
390	p := compactProtoF.GetProtocol(trans)
391	for i := 0; i < b.N; i++ {
392		ReadWriteByte(b, p, trans)
393	}
394}
395
396func BenchmarkCompactI16_1(b *testing.B) {
397	trans, err := tfv[1].GetTransport(nil)
398	if err != nil {
399		b.Fatal(err)
400	}
401	p := compactProtoF.GetProtocol(trans)
402	for i := 0; i < b.N; i++ {
403		ReadWriteI16(b, p, trans)
404	}
405}
406
407func BenchmarkCompactI32_1(b *testing.B) {
408	trans, err := tfv[1].GetTransport(nil)
409	if err != nil {
410		b.Fatal(err)
411	}
412	p := compactProtoF.GetProtocol(trans)
413	for i := 0; i < b.N; i++ {
414		ReadWriteI32(b, p, trans)
415	}
416}
417func BenchmarkCompactI64_1(b *testing.B) {
418	trans, err := tfv[1].GetTransport(nil)
419	if err != nil {
420		b.Fatal(err)
421	}
422	p := compactProtoF.GetProtocol(trans)
423	for i := 0; i < b.N; i++ {
424		ReadWriteI64(b, p, trans)
425	}
426}
427func BenchmarkCompactDouble1(b *testing.B) {
428	trans, err := tfv[1].GetTransport(nil)
429	if err != nil {
430		b.Fatal(err)
431	}
432	p := compactProtoF.GetProtocol(trans)
433	for i := 0; i < b.N; i++ {
434		ReadWriteDouble(b, p, trans)
435	}
436}
437func BenchmarkCompactString1(b *testing.B) {
438	trans, err := tfv[1].GetTransport(nil)
439	if err != nil {
440		b.Fatal(err)
441	}
442	p := compactProtoF.GetProtocol(trans)
443	for i := 0; i < b.N; i++ {
444		ReadWriteString(b, p, trans)
445	}
446}
447func BenchmarkCompactBinary1(b *testing.B) {
448	trans, err := tfv[1].GetTransport(nil)
449	if err != nil {
450		b.Fatal(err)
451	}
452	p := compactProtoF.GetProtocol(trans)
453	for i := 0; i < b.N; i++ {
454		ReadWriteBinary(b, p, trans)
455	}
456}
457
458func BenchmarkCompactBool_2(b *testing.B) {
459	trans, err := tfv[2].GetTransport(nil)
460	if err != nil {
461		b.Fatal(err)
462	}
463	p := compactProtoF.GetProtocol(trans)
464	for i := 0; i < b.N; i++ {
465		ReadWriteBool(b, p, trans)
466	}
467}
468
469func BenchmarkCompactByte_2(b *testing.B) {
470	trans, err := tfv[2].GetTransport(nil)
471	if err != nil {
472		b.Fatal(err)
473	}
474	p := compactProtoF.GetProtocol(trans)
475	for i := 0; i < b.N; i++ {
476		ReadWriteByte(b, p, trans)
477	}
478}
479
480func BenchmarkCompactI16_2(b *testing.B) {
481	trans, err := tfv[2].GetTransport(nil)
482	if err != nil {
483		b.Fatal(err)
484	}
485	p := compactProtoF.GetProtocol(trans)
486	for i := 0; i < b.N; i++ {
487		ReadWriteI16(b, p, trans)
488	}
489}
490
491func BenchmarkCompactI32_2(b *testing.B) {
492	trans, err := tfv[2].GetTransport(nil)
493	if err != nil {
494		b.Fatal(err)
495	}
496	p := compactProtoF.GetProtocol(trans)
497	for i := 0; i < b.N; i++ {
498		ReadWriteI32(b, p, trans)
499	}
500}
501func BenchmarkCompactI64_2(b *testing.B) {
502	trans, err := tfv[2].GetTransport(nil)
503	if err != nil {
504		b.Fatal(err)
505	}
506	p := compactProtoF.GetProtocol(trans)
507	for i := 0; i < b.N; i++ {
508		ReadWriteI64(b, p, trans)
509	}
510}
511func BenchmarkCompactDouble2(b *testing.B) {
512	trans, err := tfv[2].GetTransport(nil)
513	if err != nil {
514		b.Fatal(err)
515	}
516	p := compactProtoF.GetProtocol(trans)
517	for i := 0; i < b.N; i++ {
518		ReadWriteDouble(b, p, trans)
519	}
520}
521func BenchmarkCompactString2(b *testing.B) {
522	trans, err := tfv[2].GetTransport(nil)
523	if err != nil {
524		b.Fatal(err)
525	}
526	p := compactProtoF.GetProtocol(trans)
527	for i := 0; i < b.N; i++ {
528		ReadWriteString(b, p, trans)
529	}
530}
531func BenchmarkCompactBinary2(b *testing.B) {
532	trans, err := tfv[2].GetTransport(nil)
533	if err != nil {
534		b.Fatal(err)
535	}
536	p := compactProtoF.GetProtocol(trans)
537	for i := 0; i < b.N; i++ {
538		ReadWriteBinary(b, p, trans)
539	}
540}
541