#pragma once #pragma comment(lib,"rpcrt4.lib") #define _CTR_SECURE_NO_WARNINGS #include <chrono> #include <ctime> #include <iostream> #include <fstream> #include <sstream> #include <Windows.h> using namespace std; char* uuidValue; char* getUuid() { UUID newUUID; UuidCreate(&newUUID); UuidToStringA(&newUUID, (RPC_CSTR*)&uuidValue); return uuidValue; } void logFile(string fileName, int loops) { fstream wFile(fileName, ios::app); if (!wFile.is_open()) { cout << "Create or open " << fileName << " failed!" << endl; return; } uint64_t num = 0; stringstream ss; chrono::time_point<chrono::high_resolution_clock> startTime, endTime; for (int i = 0;i < loops;i++) { startTime = chrono::high_resolution_clock::now(); ss = stringstream(); for (int j = 0;j < 1000000;j++) { uuidValue = (char*)malloc(40); ss << ++num << "," << getUuid() << endl; free(uuidValue); } wFile << ss.str(); ss.str(); if (!wFile.good()) { cout << num << ",write failed!" << endl; break; } cout << uuidValue << endl; endTime = chrono::high_resolution_clock::now(); cout << num << "," << chrono::duration_cast<chrono::seconds>(endTime - startTime).count() << " seconds," << chrono::duration_cast<chrono::milliseconds>(endTime - startTime).count() << " milliseconds," << chrono::duration_cast<chrono::milliseconds>(endTime - startTime).count() << " microseconds," << chrono::duration_cast<chrono::nanoseconds>(endTime - startTime).count() << " nanoseconds!!!" << endl << endl; } wFile.close(); cout << num << ",finished in " << __FUNCTION__ << endl; } int main(int agrs, char** argv) { logFile(argv[1], atoi(argv[2])); }
标签:count,eventually,endTime,int,uuidValue,allocation,bad,startTime,include From: https://www.cnblogs.com/Fred1987/p/16767292.html