[Assorted-commits] SF.net SVN: assorted:[1381] serialization-bench/trunk/src/main.cc
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-05-07 05:41:49
|
Revision: 1381 http://assorted.svn.sourceforge.net/assorted/?rev=1381&view=rev Author: yangzhang Date: 2009-05-07 05:41:48 +0000 (Thu, 07 May 2009) Log Message: ----------- tweaks; added custom "xstream" abstraction Modified Paths: -------------- serialization-bench/trunk/src/main.cc Modified: serialization-bench/trunk/src/main.cc =================================================================== --- serialization-bench/trunk/src/main.cc 2009-05-07 05:39:31 UTC (rev 1380) +++ serialization-bench/trunk/src/main.cc 2009-05-07 05:41:48 UTC (rev 1381) @@ -15,15 +15,17 @@ using namespace commons; using namespace std; -int cnt = 1e6, reps = 3; +int cnt = 5e6, reps = 3; struct exp { void time() { + long long start = current_time_millis(); build(); - long long start = current_time_millis(); + long long mid = current_time_millis(); run(); long long end = current_time_millis(); - cout << name << ": " << end - start << " ms, " << size() << " b" << endl; + cout << name << ": " << end - mid << " ms, build " << mid - start + << " ms, " << size() << " b" << endl; } virtual void build() {} virtual void run() = 0; @@ -104,6 +106,7 @@ struct protobuf_array : virtual protobuf { char *s; protobuf_array() : s(new char[2 * cnt * sizeof(int)]) {} + ~protobuf_array() { delete [] s; } void run() { a.SerializeToArray(s, 2 * cnt * sizeof(int)); } }; @@ -126,6 +129,7 @@ struct raw_array : virtual exp { char *a; raw_array() : a(new char[cnt * sizeof(int)]) {} + ~raw_array() { delete [] a; } void run() { int *p = (int*) a; for (int i = 0; i < cnt; ++i) { @@ -134,6 +138,34 @@ } }; +//template<typename T> +//class chunk { +//public: +// chunk() : +//}; + +class xstream { +public: + xstream() : a(new char[2 * cnt * sizeof(int)]), p(a) {} + ~xstream() { delete [] a; } + inline void put(int i) { + *((int*)p) = i; + p += sizeof(int); + } +private: + char *a; + char *p; +}; + +struct xstream_exp : virtual exp { + xstream s; + void run() { + for (int i = 0; i < cnt; ++i) { + s.put(i); + } + } +}; + #define rep(x) \ for (int r = 0; r < reps; ++r) \ x().named(#x).time(); @@ -149,6 +181,7 @@ rep(protobuf_array); rep(protobufs_string); rep(raw_array); + rep(xstream_exp); #if 0 cout << "SIZES" << endl; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |