Ubuntu C++ uuid_generate vs Windows UuidCreate
1.Ubuntu,g++
#include <chrono> #include <iostream> #include <uuid/uuid.h> using namespace std; void testTime(int x); int main(int args,char**argv) { testTime(atoi(argv[1])); } void testTime(int x) { chrono::time_point<chrono::steady_clock> startTime; chrono::time_point<chrono::steady_clock> endTime; for(int i=0;i<x;i++) { startTime=chrono::steady_clock::now(); for(int j=0;j<1000000;j++) { uuid_t newUUID; uuid_generate(newUUID); } endTime=chrono::steady_clock::now(); cout<<i<<","<<chrono::duration_cast<chrono::milliseconds>(endTime-startTime).count()<<" milliseconds!"<<endl; } }
Compile
g++ -std=c++2a *.cpp -o h1 -luuid
Run
./h1 10
Snapshot
2.Windows11/VS2022/VC++
#pragma comment(lib, "rpcrt4.lib") #include <iostream> #include <chrono> #include <fstream> #include <iostream> #include <sstream> #include <string> #include <Windows.h> using namespace std; int main() { for (int j = 0;j < 10;j++) { auto startTime = chrono::system_clock::now(); for (int i = 0; i < 1000000; i++) { UUID uuid; UuidCreate(&uuid); } auto endTime = chrono::system_clock::now(); auto timeCost = chrono::duration_cast<chrono::milliseconds>(endTime - startTime).count(); cout <<j<<"," << timeCost << " milliseconds" << endl; } cin.get(); }
Release/X64,snapshot