Skip to content

Instantly share code, notes, and snippets.

@osadalakmal
Created October 28, 2012 18:38
Show Gist options
  • Save osadalakmal/3969390 to your computer and use it in GitHub Desktop.
Save osadalakmal/3969390 to your computer and use it in GitHub Desktop.
A timed serilization to StringOutputStream in google protobuf
#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