[Assorted-commits] SF.net SVN: assorted:[1155] serialization-bench
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-02-02 22:42:18
|
Revision: 1155 http://assorted.svn.sourceforge.net/assorted/?rev=1155&view=rev Author: yangzhang Date: 2009-02-02 22:42:05 +0000 (Mon, 02 Feb 2009) Log Message: ----------- added serialization benchmark Added Paths: ----------- serialization-bench/ serialization-bench/trunk/ serialization-bench/trunk/README serialization-bench/trunk/src/ serialization-bench/trunk/src/Makefile serialization-bench/trunk/src/main.cc serialization-bench/trunk/src/test.proto Added: serialization-bench/trunk/README =================================================================== --- serialization-bench/trunk/README (rev 0) +++ serialization-bench/trunk/README 2009-02-02 22:42:05 UTC (rev 1155) @@ -0,0 +1,5 @@ +Overview +-------- + +This is a benchmark comparing various systems for data serialization. +And under different workloads. Added: serialization-bench/trunk/src/Makefile =================================================================== --- serialization-bench/trunk/src/Makefile (rev 0) +++ serialization-bench/trunk/src/Makefile 2009-02-02 22:42:05 UTC (rev 1155) @@ -0,0 +1,13 @@ +all: main + +main: main.cc test.pb.h test.pb.cc + g++ -O3 -I. -g3 -Wall -o main main.cc test.pb.cc \ + -lboost_serialization-gcc43-mt -lprotobuf + +test.pb.cc test.pb.h: test.proto + protoc --cpp_out=. test.proto + +.PHONY: clean + +clean: + rm -f main test.pb.* *.out \ No newline at end of file Added: serialization-bench/trunk/src/main.cc =================================================================== --- serialization-bench/trunk/src/main.cc (rev 0) +++ serialization-bench/trunk/src/main.cc 2009-02-02 22:42:05 UTC (rev 1155) @@ -0,0 +1,96 @@ +#include "test.pb.h" +#include <arpa/inet.h> +#include <boost/archive/binary_iarchive.hpp> +#include <boost/archive/binary_oarchive.hpp> +#include <commons/time.h> +#include <fstream> +#include <iostream> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + +using namespace boost::archive; +using namespace commons; +using namespace std; + +int main() { + int count = 1e6, reps = 3; + cout << "TIMES" << endl; + for (int r = 0; r < reps; r++) { + ofstream o("raw.out", ios::out); + long long start = current_time_millis(); + for (int i = 0; i < count; i++) { + o.write(reinterpret_cast<char*>(&i), sizeof i); + } + long long end = current_time_millis(); + cout << "raw: " << end - start << endl; + } + for (int r = 0; r < reps; r++) { + ofstream o("htonl.out", ios::out); + long long start = current_time_millis(); + for (int i = 0; i < count; i++) { + int n = htonl(i); + o.write(reinterpret_cast<char*>(&n), sizeof i); + } + long long end = current_time_millis(); + cout << "htonl: " << end - start << endl; + } + for (int r = 0; r < reps; r++) { + ofstream o("fstream.out", ios::out); + long long start = current_time_millis(); + for (int i = 0; i < count; i++) { + int n = htonl(i); + o << n << " "; + } + long long end = current_time_millis(); + cout << "fstream: " << end - start << endl; + } + for (int r = 0; r < reps; r++) { + filebuf b; + b.open("boost.out", ios::out); + binary_oarchive o(b); + long long start = current_time_millis(); + for (int i = 0; i < count; i++) { + o & i; + } + long long end = current_time_millis(); + cout << "boost: " << end - start << endl; + } + for (int r = 0; r < reps; r++) { + ofstream o("protobuf.out", ios::out); + varray a; + long long start = current_time_millis(); + for (int i = 0; i < count; i++) { + a.add_v(i); + } + a.SerializeToOstream(&o); + long long end = current_time_millis(); + cout << "protobuf: " << end - start << endl; + } + for (int r = 0; r < reps; r++) { + ofstream o("manyprotos.out", ios::out); + long long start = current_time_millis(); + for (int i = 0; i < count; i++) { + varray a; + a.add_v(i); + a.SerializeToOstream(&o); + } + long long end = current_time_millis(); + cout << "many protobufs: " << end - start << endl; + } + + cout << "SIZES" << endl; + vector<string> paths; + paths.push_back("raw.out"); + paths.push_back("htonl.out"); + paths.push_back("fstream.out"); + paths.push_back("boost.out"); + paths.push_back("protobuf.out"); + paths.push_back("manyprotos.out"); + for (size_t i = 0; i < paths.size(); i++) { + struct stat s; + stat(paths[i].c_str(), &s); + cout << paths[i] << ": " << s.st_size << endl; + } + return 0; +} Added: serialization-bench/trunk/src/test.proto =================================================================== --- serialization-bench/trunk/src/test.proto (rev 0) +++ serialization-bench/trunk/src/test.proto 2009-02-02 22:42:05 UTC (rev 1155) @@ -0,0 +1,4 @@ +option optimize_for = SPEED; +message varray { + repeated int32 v = 1; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |