#define ENABLE_BITWISE_SERIALIZATION #include "BigStruct.h" #pragma warning(disable:4244) #pragma warning(disable:4996) #include #include #include int numObjectsToSerialize = 10000; void serializeBigStruct(); void serializeBigStructArray(); void serializeBigStructVector(); int main(int argc, char* argv[]) { { // The following is to perform type registration of BigStruct within boost serialization... std::ostringstream outStream; boost::archive::binary_oarchive binOutArchive(outStream, boost::archive::no_header); BigStruct bigStruct; memset(&bigStruct, 0, sizeof(bigStruct)); binOutArchive << bigStruct; } // Different test cases serializeBigStructArray(); serializeBigStruct(); serializeBigStructVector(); return 0; } void serializeBigStruct() { std::ostringstream outStream; boost::archive::binary_oarchive binOutArchive(outStream, boost::archive::no_header); BigStruct bigStruct; memset(&bigStruct, 0, sizeof(bigStruct)); std::cout << "\n*** Serializing 1 BigStruct object " << numObjectsToSerialize << " times ***\n"; std::clock_t c_start = std::clock(); // Serialize many times, to have a significant elapsed time for (int i = 0; i < numObjectsToSerialize; ++i) { binOutArchive << bigStruct; } std::clock_t c_end = std::clock(); double elapsed_time_in_ms = 1000.0 * (c_end - c_start) / CLOCKS_PER_SEC; std::cout << "CPU time used: " << elapsed_time_in_ms << " ms" << std::endl; } void serializeBigStructArray() { std::ostringstream outStream; boost::archive::binary_oarchive binOutArchive(outStream, boost::archive::no_header); BigStruct bigStructArray[1]; memset(&bigStructArray, 0, sizeof(bigStructArray)); std::cout << "\n*** Serializing an array of 1 BigStruct object " << numObjectsToSerialize << " times ***\n"; std::clock_t c_start = std::clock(); // Serialize many times, to have a significant elapsed time for (int i = 0; i < numObjectsToSerialize; ++i) { binOutArchive << bigStructArray; } std::clock_t c_end = std::clock(); double elapsed_time_in_ms = 1000.0 * (c_end - c_start) / CLOCKS_PER_SEC; std::cout << "CPU time used: " << elapsed_time_in_ms << " ms" << std::endl; } void serializeBigStructVector() { std::ostringstream outStream; boost::archive::binary_oarchive binOutArchive(outStream, boost::archive::no_header); std::vector bigStructVec; for (int i = 0; i < numObjectsToSerialize; ++i) { BigStruct bigStruct; memset(&bigStruct, 0, sizeof(bigStruct)); bigStructVec.push_back(bigStruct); } std::cout << "\n*** Serializing a vector of " << numObjectsToSerialize << " BigStruct objects once ***\n"; std::clock_t c_start = std::clock(); binOutArchive << bigStructVec; std::clock_t c_end = std::clock(); double elapsed_time_in_ms = 1000.0 * (c_end - c_start) / CLOCKS_PER_SEC; std::cout << "CPU time used: " << elapsed_time_in_ms << " ms" << std::endl; }