blob: eede9cebe7b8791b4ad2b0ed162e69a0e38e65a1 [file] [log] [blame]
David Reiss2a4bfd62008-04-07 23:45:00 +00001#include <iostream>
2#include <cmath>
3#include <transport/TTransportUtils.h>
4#include <protocol/TBinaryProtocol.h>
5#include <protocol/TJSONProtocol.h>
6#include "gen-cpp/DebugProtoTest_types.h"
7#include <time.h>
8#include "../lib/cpp/src/protocol/TDebugProtocol.h"
9
10class Timer {
11public:
12 timeval vStart;
13
14 Timer() {
15 gettimeofday(&vStart, 0);
16 }
17 void start() {
18 gettimeofday(&vStart, 0);
19 }
20
21 double frame() {
22 timeval vEnd;
23 gettimeofday(&vEnd, 0);
24 double dstart = vStart.tv_sec + ((double)vStart.tv_usec / 1000000.0);
25 double dend = vEnd.tv_sec + ((double)vEnd.tv_usec / 1000000.0);
26 return dend - dstart;
27 }
28
29};
30
31int main() {
32 using namespace std;
33 using namespace thrift::test::debug;
34 using namespace facebook::thrift::transport;
35 using namespace facebook::thrift::protocol;
36 using namespace boost;
37
38 OneOfEach ooe;
39 ooe.im_true = true;
40 ooe.im_false = false;
41 ooe.a_bite = 0xd6;
42 ooe.integer16 = 27000;
43 ooe.integer32 = 1<<24;
44 ooe.integer64 = (uint64_t)6000 * 1000 * 1000;
45 ooe.double_precision = M_PI;
46 ooe.some_characters = "JSON THIS! \"\1";
47 ooe.zomg_unicode = "\xd7\n\a\t";
48 ooe.base64 = "\1\2\3\255";
49
50 shared_ptr<TMemoryBuffer> buf(new TMemoryBuffer());
51
52 int num = 1000000;
53
54 {
55 Timer timer;
56
57 for (int i = 0; i < num; i ++) {
58 buf->resetBuffer();
59 TBinaryProtocol prot(buf);
60 ooe.write(&prot);
61 }
62 cout << "Write: " << num / (1000 * timer.frame()) << " kHz" << endl;
63 }
64
65 uint8_t* data;
66 uint32_t datasize;
67
68 buf->getBuffer(&data, &datasize);
69
70 {
71
72 Timer timer;
73
74 for (int i = 0; i < num; i ++) {
75 OneOfEach ooe2;
76 shared_ptr<TMemoryBuffer> buf2(new TMemoryBuffer(data, datasize));
77 //buf2->resetBuffer(data, datasize);
78 TBinaryProtocol prot(buf2);
79 ooe2.read(&prot);
80
81 //cout << facebook::thrift::ThriftDebugString(ooe2) << endl << endl;
82 }
83 cout << " Read: " << num / (1000 * timer.frame()) << " kHz" << endl;
84 }
85
86
87 return 0;
88}