#include #include #include #include #include #define BOOST_ARCHIVE_SOURCE #include #include #include #include #include #include #include using namespace std; using namespace boost::archive; int main(int argc, char* argv[]) { char* endptr = 0; long elements; if (argc > 1) { elements = strtol(argv[1], &endptr, 10); } else { elements = 70000; } list lst; list lst2; for (int j = 1; j <= elements; ++j) { lst.push_back(j); } filebuf fb; fb.open("ofile", ios_base::out | std::ios_base::binary); binary_oarchive oa(fb); timeval before_tv, after_tv; struct timezone tz; gettimeofday(&before_tv, &tz); oa << lst; gettimeofday(&after_tv, &tz); if (before_tv.tv_sec != after_tv.tv_sec) { after_tv.tv_usec += 1000000; } long diff = after_tv.tv_usec - before_tv.tv_usec; //cout << "Output took (microseconds) " << diff << endl; fb.close(); std::ifstream ifs("ofile", std::ios_base::binary); binary_iarchive ia(ifs); gettimeofday(&before_tv, &tz); ia >> lst2; gettimeofday(&after_tv, &tz); if (before_tv.tv_sec != after_tv.tv_sec) { after_tv.tv_usec += 1000000; } diff = after_tv.tv_usec - before_tv.tv_usec; cout << "Input took (microseconds) " << diff << endl; if (lst != lst2) { cout << "The two lists are not logically equivalent.\n"; } return 1; }