Created
October 28, 2012 18:38
-
-
Save osadalakmal/3969390 to your computer and use it in GitHub Desktop.
A timed serilization to StringOutputStream in google protobuf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "gtest/gtest.h" | |
#include <fstream> | |
#include <chrono> | |
#include <iomanip> | |
#include "person.pb.h" | |
#include "google/protobuf/io/zero_copy_stream_impl.h" | |
TEST(Protobuf,SimpleIOString) { | |
using namespace std; | |
Person person; | |
person.set_id(12345); | |
person.set_name("bob"); | |
person.set_email("boba@example.com"); | |
std::string data2; | |
data2.reserve(512); | |
google::protobuf::io::StringOutputStream sos(&data2); | |
typedef std::chrono::high_resolution_clock Clock; | |
auto t1 = Clock::now(); | |
for (auto i=100000;i>0;i--) { | |
person.SerializeToZeroCopyStream(&sos); | |
} | |
auto t2 = Clock::now() - t1; | |
std::cout << t2.count() << '\n'; | |
Person person_2; | |
//code to ASSERT equality of person2 and person | |
} | |
TEST(Protobuf,SimpleIOArray) { | |
using namespace std; | |
Person person; | |
person.set_id(12345); | |
person.set_name("bob"); | |
person.set_email("boba@example.com"); | |
char data[512]; | |
google::protobuf::io::ArrayOutputStream aos(data,512); | |
typedef std::chrono::high_resolution_clock Clock; | |
auto t1 = Clock::now(); | |
for (auto i=100000;i>0;i--) { | |
person.SerializeToZeroCopyStream(&aos); | |
} | |
auto t2 = Clock::now() - t1; | |
std::cout << t2.count() << '\n'; | |
Person person_2; | |
//code to ASSERT equality of person2 and person | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment